1 / 24

Class diagram

Class diagram. Purpose of Structural Models. Class diagrams represent Generic Categories (classes) of things (objects) Define relationships among Generic Categories (classes) of things (objects). Classes. Generic type of thing Objects are the individual things

Télécharger la présentation

Class diagram

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

  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 Class Attributes Operations

  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 studies► Student Course

  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 memberOf ► Seminar Student

  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 deliveredFor ► Seminar Module

  18. PartTimeStudent Student Type Five Inheritance • Specialisation / generalisation between two classes • Example • Part Time Student is a type of Student

  19. Visibility

  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? 1..* is taking  6 Student Module association class is taking mark : Integer

  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 0..* employee  manages 0..1

  23. Class v. Object Diagram Staff • full symbol for an object is a box with 3 compartments • class name • attributes • operations staffName staffID staffstartdate staffdept an instance symbol shows both instance and class name underlined with a colon to separate AkhtarAli:Staff staffName=Akhtar Ali staffID=313 staffstartdate=140800 staffdept=SDE 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

More Related