Presentation is loading. Please wait.

Presentation is loading. Please wait.

بسم الله الرحمن الرحيم ” اللهم أنت ربي لا إله إلا أنت خلقتني و أنا عبدك وأنا على عهدك ووعدك ما استطعت ، أعوذ بك من شر ما صنعت ، أبوء لك بنعمتك على و أبوء.

Similar presentations


Presentation on theme: "بسم الله الرحمن الرحيم ” اللهم أنت ربي لا إله إلا أنت خلقتني و أنا عبدك وأنا على عهدك ووعدك ما استطعت ، أعوذ بك من شر ما صنعت ، أبوء لك بنعمتك على و أبوء."— Presentation transcript:

1 بسم الله الرحمن الرحيم ” اللهم أنت ربي لا إله إلا أنت خلقتني و أنا عبدك وأنا على عهدك ووعدك ما استطعت ، أعوذ بك من شر ما صنعت ، أبوء لك بنعمتك على و أبوء لك بذنبي فاغفر لي فإنه لا يغفر الذنوب إلا أنت ”.

2 Class Diagrams

3 What is a Class Diagrams?  Class diagrams are the backbone of almost every object oriented method, including UML. They describe the static structure of a system.  A class diagram describes the types of objects in the system and the various kinds of static relationships that exist among them.

4 Class Diagrams A class diagram shows:  Classes Attributes Methods  Interfaces  Collaborations  Relationships: Dependency, Generalization, Association A class diagram is a STATIC view of system

5 Classes  A class is the description of a set of objects having similar attributes, operations (behavior), and relationships.

6 Basic Class Diagrams Window size: Size visibility: boolean display() hide() Class Name Attributes Operations

7 Basic Class Diagrams +public #protected -private / derived $ static Visibility Attribute Name [Multiplicity]:Type = Initial Value Visibility Method Name (Parameter List) : Return-List Class Scope Variable

8 Basic Class Diagram (Example) Person + name : String - ssn : String # birthday : Date / age : int +getName : String -calculateAge : int

9 Associations  A semantic relationship between two or more classes that specifies connections among their instances.  A structural relationship specifying that objects of one class are connected to objects of a second (possibly the same) class.  Example: “ An Employee works for a Company ”.

10 Associations (cont.)  An association between two classes indicates that objects at one end of an association “ recognize ” objects at the other end and may send messages to them. Borrower Book 31 currBorrbk[]

11 Association (Java implementation) public class Borrower { Book bk[]; int numBooks; … public Borrower() { numBooks = 0; bk = new Book[3]; } // methods that update bk public void borrowBook( Book b ) { bk[numBooks] = b; numBooks++; b.setBorrower( this ); } public class Book { Borrower currBorr; public void setBorrower( Borrower bw ) { currBorr = bw; }

12 Aggregation  A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts. Models a “ is a part-part of ” relationship. Whole Part Car Wheel 4 wheels

13 Aggregation (Java implementation) public class Car { private Wheel wheels[];... // wheel objects are created externally and // passed to the constructor public Car( Wheel w1, Wheel w2, … ) { // we can check w1, w2, etc. for null // to make sure wheels exist wheels = new Wheel[4]; wheels[0] = w1; wheels[1] = w2; … }

14 Composition  A strong form of aggregation: The whole is the sole owner of its part:  The part object may belong to only one whole Multiplicity on the whole side must be one The life time of the part is dependent upon the whole  The composite must manage the creation and destruction of its parts LinePoint 3..* 2 Polygon

15 Composition (Java implementations) public class Car { private Wheel wheels[];... public Car() { wheels = new Wheel[4]; // Wheels are created in Car … wheels[0] = new Wheel(); wheels[1] = new Wheel(); … }... }

16 Generalization  Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class) “ is kind of ” relationship Shape Circle Super Class Sub Class An abstract class Generalization relationship

17 Generalization  A sub-class inherits from its super- class: Attributes. Operations. Relationships.  A sub-class may: Add attributes and operations. Add relationships. Refine (override) inherited operations.

18 Generalization (Java implementation)  public abstract class Shape { public abstract void draw();... }  public class Circle extends Shape { public void draw() {... }... }

19 Dependency  A dependency indicates a semantic relation between two or more classes in which a change in one may force changes in the other although there is no explicit association between them  A stereotype may be used to denote the type of the dependency Parser getTransaction() uses Bank processTransactions ()

20 Dependency (Java implementation) public class Bank { … public void processTransactions() { // Parser p is a local variable … Parser p = new Parser( … ); … p.getTransaction(); … } … }

21 Realization  A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol).  An interface can be realized by many classes.  A class may realize many interfaces. LinkedList > List LinkedList List

22 Realization (Java implementation)  public interface List { boolean add(Object o);... }  public class LinkedList implements List { public boolean add(Object o) {... }... }

23 Basic Class Diagrams Superclass Subclass Inheritance (Generalization) (is-a, kind-of) Class with parts Assembly Class Aggregation (Part-Of) Association (relationship) Class with parts Assembly Class Dependency Class A Class B name Interface Concrete Class Realization

24  Multiplicity The number of instances of the class, next to which the multiplicity expression appears, that are referenced by a single instance of the class that is at the other end of the association path. Indicates whether or not an association is mandatory. Provides a lower and upper bound on the number of instances.

25 Multiplicity Indicators Exactly one1 Zero or more (unlimited)* (0..*) One or more1..* Zero or one (optional association) 0..1 Specified range2..4

26 Computer: Computer PrintServer: PrintServer Printer: Printer print(file) User: User print (filename) Queue: Queue [printer free] print(file) [printer busy] store(file)

27 Computer print(filename) PrintServer status(): integer print(file) Printer print(file) Queue store(file) uses Managed by

28


Download ppt "بسم الله الرحمن الرحيم ” اللهم أنت ربي لا إله إلا أنت خلقتني و أنا عبدك وأنا على عهدك ووعدك ما استطعت ، أعوذ بك من شر ما صنعت ، أبوء لك بنعمتك على و أبوء."

Similar presentations


Ads by Google