Chapter 4 Class & Object Diagram.pdf
Document Details
Uploaded by SubstantiveLutetium
2019
Tags
Full Transcript
Benghazi University Faculty of Information Technology Software Design Chapter 4 “Class & Object Diagram” Prepared by MSc. Howayda Elmarzaki SE321 Group “C” 2019-2020 We use the class diagram to model the static structure of a system,...
Benghazi University Faculty of Information Technology Software Design Chapter 4 “Class & Object Diagram” Prepared by MSc. Howayda Elmarzaki SE321 Group “C” 2019-2020 We use the class diagram to model the static structure of a system, thus describing the elements of the system and the relationships between them. It is applied in various phases of the software development process. The level of detail of the class diagram is different in each phase. In the early project phases, a class diagram allows you to create a conceptual view of the system and to define the vocabulary to be used. You can then refine this vocabulary into a programming language up to the point of implementation. Object diagram allow you to depict concrete objects that appear in a system at a specific point in time. Classes provide schemas for characterizing objects and objects are instances of classes. Object diagram shows the actual representation of data in classes. A class is represented by a rectangle that can be subdivided into multiple compartments. The first compartment must contain the name of the class. The second compartment of the rectangle contains the attributes of the class. And the third compartment the operations of the class. An attribute has at least a name. The type of the attribute may be specified after the name using : Type. Possible attribute types include primitive data types, such Type as integer and string. To define a default value for an attribute, you specify = Default, where Default is a user-defined value or expression. Operations are the methods that the class executed. When an operation is called in a program, the behavior assigned to this operation is executed. The class diagram is not suitable for describing the behavior of objects in detail. class diagram only models signatures of the operations that the objects provide. class diagram does not model how these operations are actually implemented. In a class diagram, the operation name is followed by a list of parameters in parentheses. The list itself may be empty. The optional return value of an operation is specified with the type of the return value. The visibility of attributes and operations specifies who is and who is not permitted to access them. Only an object itself knows the values of attributes that are marked as private. In contrast, anyone can view attributes marked as public. Access to protected attributes is reserved for the class itself and its subclasses. If a class has a package attribute, only classes that are in the same package as this class may access this attribute. Visibilities are used to realize information hiding. Marking the attributes that represent the state of an object as private protects this state against unauthorized access. Multiplicity shows the number of objects from one class that relate with a number of objects in an associated class. One – to - one : each student must have exactly one ID card One – to – many: A single student can take many courses One – to – many (Specified Range): A single student can take 3 to 6 courses. many– to – many: many students can be in class and a class can has many students A binary association allows us to associate the instances of two classes with one another. The relationships are shown as edges (solid line) between the partner classes involved. The edge can be labeled with the name of the association optionally followed by the reading direction, a small, black triangle. navigability indicates that an object knows its partner objects and can therefore access their visible attributes and operations. The reading direction indicates that professors give lectures for students. The navigability specified indicates that students can access the visible characteristics of professors whose lectures they attend. In contrast, a professor cannot access the visible characteristics of the students who attend the professor’s lecture. If more than two partner objects are involved in a relationship, you can model this using an n-ary association. An n-ary association is represented with a hollow diamond in the center. The diamond is connected with all partners of the relationship by means of an undirected edge. The name of the association is specified next to the diamond. An aggregation is a special form of association that is used to express that instances of one class are parts of an instance of another class. UML differentiates between two types: shared aggregation and composition. a shared aggregation expresses a weak belonging of the parts to a whole, meaning that parts also exist independently of the whole. The use of a composition expresses that a specific part can only be contained in at most one composite object at one specific point in time. Different classes often have common characteristics. We can use a generalization relationship to highlight commonalities between classes. Meaning that we no longer have to define these common characteristics multiple times. Conversely, we can use the generalization to derive more specific classes from existing classes. The generalization relationship expresses that the characteristics (attributes and operations) and associations that are specified for a general class (superclass) are passed on to its subclasses. Therefore, the generalization relationship is also referred to as inheritance. This means that every instance of a subclass is simultaneously an indirect instance of the superclass. Information system of a university Scenario Information system of a university Identifying the classes Information system of a university Identifying the attributes Information system of a university Final Class diagram Thank you for your Attention