Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class diagram. Purpose of Structural Models Class diagrams represent –Generic Categories (classes) of things (objects) –Define relationships among Generic.

Similar presentations


Presentation on theme: "Class diagram. Purpose of Structural Models Class diagrams represent –Generic Categories (classes) of things (objects) –Define relationships among Generic."— Presentation transcript:

1 Class diagram

2 Purpose of Structural Models Class diagrams represent –Generic Categories (classes) of things (objects) –Define relationships among Generic Categories (classes) of things (objects)

3 Classes Generic type of thing Objects are the individual things Classes are templates for creating instances or objects –Concrete –Abstract Typical examples: –Application domain, user interface, data structure, file structure, operating environment, document, and multimedia classes

4 Attributes Facts related to a type of thing –Attributes of a class –Class – Car Attribute may include: Make, Model, Engine size, etc Only attributes important to the task should be included

5 Operations Behavior types of things do –Class – Car, Operation – accelerate(), break(), etc Action that instances/objects can take – defined by the class Focus on relevant problem-specific operations (at this point) Quick Exercise – in 1 minute

6 Exercise 1 - Classes A Cinema shows films. Each film has a title, a producer, a director, a length, certificate and a genre. Patrons watch films at the cinema. Patrons are either adults or children and have a name and an age. To see a film a patron has to buy a ticket. A ticket has a price, a time and is for a film.

7 Exercise 1 – Solution Template ClassAttributes

8 Class Diagram Mechanism for visualising classes Became truly central within all object oriented methods A Class Diagram shows –Classes Attributes Operations –Relationships Which are consistent over time Shows the structure of things and ideas in a system

9 Basic Diagram Identify Classes Draw a rectangle for each class Name it

10 Add attributes and operations For each class identified Identify attributes –Facts associated with classes Identify operations/methods –Actions objects of the classes do Re-factor –Are the attributes in the right class? –Are the operations in the right class?

11 Simple Class Diagram Attributes Operations Class

12 Relationships Some Classes can be related Relationships have difference types Generalization / Specialization Aggregation Composition Association

13 Relationships Classes do not exist in isolation It is important to consider how they –Interact –Relate Tend to be VERBS Five principal types of relationships

14 Type One - Dependency Where one class must know about another Example: – Prospective student knows of a course Not commonly used Used more commonly in design / implementation –Java – import javax.swing.*; Car Wheel

15 Type Two - Association Classes associated with / related to one another Example –Student studies a course Very Commonly used “Default” type of relationship StudentCourse studies►

16 Type Three - Aggregation Classes made up of other classes “Part of” relationship Objects of classes that can exist in their own right Example –Student is a member of a seminar group Seminar Student memberOf ►

17 Type Four - Composition Class is an integral part of another “Integral part of” relationship Object of classes that cannot exist without the other Example: –Seminar is delivered for a Module SeminarModule deliveredFor ►

18 Type Five Inheritance Specialisation / generalisation between two classes Example –Part Time Student is a type of Student StudentPartTimeStudent

19 Visibility DescriptionSymbo l PublicIs directly accessible by an instance of any class + PrivateMay only be used by an instance of the class that includes it - Protecte d May be used either by an instance of the class that includes it or by a subclass of that class # PackageIs directly accessible only by instances of a class in the same package ~

20 Association Classes Sometimes the way in which objects of a class are associated is just as important as the objects of a class themselves Consider the association between Student and Module. Where should our system record the student’s marks on for each student on each module? StudentModule 1..*6 is taking  is taking mark : Integer association class

21 Constraints a constraint is a condition that has to be satisfied Use with care –Too much text on a diagram –Can be over used

22 Recursive Association - is allowed, and can be useful ! an employee, as a manager, may manage other employees; each employee may be managed by another employee employee  manages 0..* 0..1

23 Class v. Object Diagram Staff staffName staffID staffstartdate staffdept AkhtarAli:Staff staffName=Akhtar Ali staffID=313 staffstartdate=140800 staffdept=SDE full symbol for an object is a box with 3 compartments class name attributes operations an instance symbol shows both instance and class name underlined with a colon to separate in an instance symbol, both attribute names and values are given

24 ที่มา IS0514, Business Systems Development Tools and Techniques, Northumbria University : Dr. M. Akhtar Ali


Download ppt "Class diagram. Purpose of Structural Models Class diagrams represent –Generic Categories (classes) of things (objects) –Define relationships among Generic."

Similar presentations


Ads by Google