Cap 315

download Cap 315

of 8

Transcript of Cap 315

  • 8/2/2019 Cap 315

    1/8

    MODEL HOMEWORK # 1

    CAP306: Computer Networks

    DOA: DOS:

    DOT: DOE:

    Homework Title / No. : ____1____________________________Course Code : _cap 412

    cap 412

    CAP 315____

    Course Instructor: _Avinish Sir ___________ Course Tutor (if applicable) : ____________

    Students Roll No.__RD3801A08______________ Section No. : _D3801__________________

    Declaration:I declare that this assignment is my individual work. I have not copied from any other students work or from any

    other source except where due acknowledgment is made explicitly in the text, nor has any part been written for

    me by another person.

    Students Signature :

    __Himanshu Gautam___

    Evaluators comments: _____________________________________________________________________

    Marks obtained : ___________ out of ______________________

    Part A

    Q:-1 What are the basic principles of object orientation?

    Answer: - ABSTRACTION: The abstraction principles used in the object-oriented approachare: Classification/instantiation, aggregation/decomposition, generalization/specialization andgrouping/individualization. By providing support for the abstraction principles, the object-

    oriented paradigm makes it possible to use conceptual modeling as an efficient tool during thephases of analysis and design. Conceptual modeling can be defined as the process oforganizing our knowledge of an application domain into hierarchical rankings or orderings ofabstraction.

    ENCAPSULATION: Often, encapsulation is referred to as "information hiding." An object"hides" the implementation of its behavior behind its interface or its "public face." Other objectscan use its behavior without having detailed knowledge of its implementation. Objects know

  • 8/2/2019 Cap 315

    2/8

    only the kind of operations they can request other objects to perform. This allows softwaredesigners to abstract from irrelevant details and concentrate on what objects will perform.

    MODULARITY: Modularity is another way of managing complexity by dividing large andcomplex systems into smaller and manageable pieces. A software designing

    method is modular if it allows designers produce software systems by usingindependent elements connected by a coherent, simple structure. [Mey88]defines a software construction method to be modular if it satisfies the fivecriteria:Modular Protection

    Modular Understandability

    Modular Composability

    Modular Continuity

    Modular Decomposabiiity

    HIERARCHY

    Hierarchy is a ranking or ordering of abstractions.

    Types of hierarchies:

    1. Class

    2. Aggregation

    3. Containment

    4. Inheritance

    5. Partition

    6. Specialization

    Q2:- Why we use package, explain with the diagram?Answer: - Package diagrams are used to reflect the organization of packages and theirelements. When used to represent class elements, package diagrams provide a visualizationof the namespaces. The most common use for package diagrams is to organize use casediagrams and class diagrams, although the use of package diagrams is not limited to theseUML elements.

  • 8/2/2019 Cap 315

    3/8

    Packages can be built to represent either physical or logical relationships. When choosing toinclude classes in specific packages, it is useful to assign the classes with the sameinheritance hierarchy to the same package. There is also a strong argument for includingclasses that are related via composition, and classes that collaborate with them, in the samepackage.

    Q:-3 Role of hierarchy in object orientation.

    Answer: - hierarchies in object-oriented programming

    Its often the case that the building blocks of a software project form similar conceptualrelationship hierarchies. Consider for example the following build-in LabVIEW types.

    All of these build-in types are numeric types. Furthermore EXT, DBL, SGL, CXT, CDB andCSG are floating point numbers whereas I64, I32, I16, I8, U64, U32, U16 and U8 are integer

  • 8/2/2019 Cap 315

    4/8

    numbers. We can divide integers to signed and unsigned integers and floating point numbersto real and complex numbers. Indeed these numeric types can be considered to form aconceptual hierarchy similar to one below.

    Object-oriented programming allows the developer to specify this kind of conceptualhierarchies in software architecture. Each box in the above image can be considered to be a

    class. Remember from my last article that classes are building blocks in object-orientedprogramming that encapsulate both data and functionality.

    This concept of hierarchies is called inheritance in object-oriented programming. The wordinheritance comes from the fact that the classes in the hierarchy inherit properties, functionalityand interfaces of their parents and all other ancestors. The diagram itself is called a classdiagram as it represents the relations between different classes.

    In object-oriented programming developers can define class hierarchies that define therelations of classes. Decedent classes inherit the functionality, the interface and the data typeof all the ancestor classes. Although it didnt yet become clear, class hierarchies andinheritance is one of the key substances in object-oriented programming. Class hierarchies

    greatly enhance code reuse and allow creating more intuitive software architectures.

    Q:-4 explain the relationship between Classes and objects?.

    Answer: - They look very much same but are not same. Class is a definition, while object isa instance of the class created. Class is a blue print while objects are actual objects existing inreal world. Example we have class CAR which has attributes and methods like Speed, Brakes,Type of Car etc. Class CAR is just a prototype, now we can create real time objects which canbe used to provide functionality.Example we can create a TATA car object with 100 km speed and urgent brakes.

    Q:-5 What is the need define the class scope and how we do define the class scope?

    Answer: - the operator of scope (::, two colons). It is used to define a member of a class fromoutside the class definition itself.

    #include

    using namespace std;

  • 8/2/2019 Cap 315

    5/8

    class CRectangle {

    int x, y;

    public:

    void set_values (int,int);

    int area () {return (x*y);}

    };

    void CRectangle::set_values (int a, int b) {

    x = a;

    y = b;

    }

    int main () {CRectangle rect;

    rect.set_values (3,4);

    cout

  • 8/2/2019 Cap 315

    6/8

    Part B

    Q:-6 Explain the basic Strengths of object orientation?

    Answer: - 1. A single paradigm

    2. facilitates architectural and code reuse.

    3. Models more closely reflect the real world

    (i) more accurately describe corporate data and processes

    (ii) decomposed based on natural partitioning

    (iii) easier to understand and maintain

    4. stability A small change in requirements does not mean massive changes in the systemunder development.

    Q:-7 Explain the concept of Encapsulation with the help of an diagram?.

    Answer: - Encapsulation means as much as shielding. Each object-oriented object has a shieldaround it. Objects can't 'see' each other. They can exchange things though, as if they areinterconnected through a hatch. It separates the external aspects of an object from theinternal implementation details of the object, which are hidden from other objects. The objectencapsulates both data and the logical procedures required to manipulate the data.

    Example of Encapsulation Concept.

  • 8/2/2019 Cap 315

    7/8

    Q:-8 What is Class diagram? Where we will use the class diagrams?

    Answer: - The purpose of a class diagram is to depict the classes within a model. In an objectoriented application, classes have attributes (member variables), operations (memberfunctions) and relationships with other classes. The UML class diagram can depict all thesethings quite easily. The fundamental element of the class diagram is an icon the represents a

    class.

    Q:-9 Explain Dependency , association, Generalization ?

    Answer: -

    ASSOCIATION

    Objects are often associated with, or related to, other objects. For example, as you see inFigure 2 several associations exist: Students are ON WAITING LIST for seminars, professorsINSTRUCT seminars, seminars are an OFFERING OF courses, a professor LIVES AT anaddress, and so on. Associations are modeled as lines connecting the two classes whoseinstances (objects) are involved in the relationship.

    When you model associations in UML class diagrams, you show them as a thin line connectingtwo classes. Associations can become quite complex; consequently, you can depict somethings about them on your diagrams. The label, which is optional, although highlyrecommended, is typically one or two words describing the association. For example,

    professors instruct seminars.

    Notation for associations.

  • 8/2/2019 Cap 315

    8/8

    DEPENDENCY

    Sometimes the relationship between a two classes is very weak. They are not implementedwith member variables at all. Rather they might be implemented as member functionarguments. Consider, for example, the Draw function of the Shape class. Suppose that thisfunction takes an argument of type DrawingContext.

    a dashed arrow between the Shape class and the DrawingContext class. This is thedependency relationship. In Booch94 this was called a using relationship. This relationshipsimply means that Shape somehow depends upon DrawingContext. In C++ this almost alwaysresults in a #include.

    GENERALIZATION

    Also called an "is a" relationship, because the child class is a type of the parent class.Generalization is the basic type of relationship used to define reusable elements in the class

    diagram. Literally, the child classes "inherit" the common functionality defined in the parentclass.