Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class Diagrams.

Similar presentations


Presentation on theme: "Class Diagrams."— Presentation transcript:

1 Class Diagrams

2 CLASS DIAGRAM *A class diagram defines the classes of objects in the system, the attributes and operations of the classes, and the relationships between classes. هذا الرسم يوضح مجموعة ال classes و كل من المتغيرات و الدوال الموجودة بها و العلاقة بينها *It is a static model, describing what exists and what attributes and behavior it has, rather than how something is done. هو احد طرق التمثيل الثابته التي تعرض مجموعه المتغيرات و الدوال دون وصف كيفية انجاز مهمه محدده

3 Essential Elements of a UML Class Diagram
المكونات الاساسية لهذا النظام هي : Class. Attributes. Operations. Relationships. Associations. Aggregation & Composition. Generalization. Dependency.

4 Classes A class is the description of a set of objects having similar “attributes”, “operations”, relationships and behavior. ال class: هو وصف لمجموعه الحالات (objects) لها نفس المتغيرات و الدوال و العلاقات فيما بينها Class Name Drink Window Attributes Size: size Visibility: boolean Name:String Price:Double Display() hideI() Operations CheckDrink()

5 Modeling Visibility Visibility: An enumeration whose value (public, protected, package, or private) denotes how the model element to which it refers may be Seen outside its enclosing namespace. Its applied to both attributes and operations in a class الظهور: هو رقم بأخذ القيمه (public, protected, package, or private) لتوضيح كيفية ظهور مكونات ال class للاجزاء الاخرى من النظام و يتم اعطاء هذه القيمة للمتغيرات و الدوال على حد سوا Symbol Visibility Level - Private ~ Package + Public # Protected

6 Elements of class diagram…
Class name compartment Client - companyAddress - company - companyFax + companyName # companyTelephone private Attributes compartment public Operations compartment + getClientInfo( ) protected - updateClientInfo( ) 6

7 Associations A semantic relationship between two or more classes that specifies connections among their instances. هي علاقة بين اثنين او اكثر من ال classes لبيان ان هنالك علاقة بينها او بين ال objects التابعه لها 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”.

8 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. هذه العلاقة بين ال classes توضح ان كل منهما يتطيع التعرف علي متغيرات و دوال الثاني و يستطيع ارسال قيم له 1 3 Borrower Book currBorr bk[]

9 Association (Java implementation)
public class Book { Borrower currBorr; public void setBorrower( Borrower bw ) { currBorr = bw; } 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 );

10 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. هي نوع خاص من العلاقات لبيان العلاقة بين الكل و اجزاءه 4 Car Wheel wheels Whole Part

11 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; … }

12 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 في هذه العلاقة وجود الجزء او عدمه يعتمد على الكل حيث يتحكم في إنشاء و حذف الاجزاء Line Point 3..* 2 Polygon

13 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(); … }

14 Generalization relationship
Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class) “is kind of” relationship هذه العلاقة تبين ان subclass يمكن ان تحل محل ال super-class An abstract class Shape Super Class Generalization relationship Sub Class Circle

15 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.

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

17 processTransactions ()
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 ()

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

19 <<interface>> List
Realization A realization relationship indicates that one class implements a behavior specified by another class (an interface or protocol). هذا العلاقة تعني ان احد ال classes يقوم بتعريف مكونات دوال class اخر An interface can be realized by many classes. A class may realize many interfaces. LinkedList <<interface>> List LinkedList List

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

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

22 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. عدد الحالات من class محدد تظهر على كل طرف من سهم العلاقة لبيان نوعها Indicates whether or not an association is mandatory. توضح هل العلاقة اجبارية ام لا Provides a lower and upper bound on the number of instances. توضح اعلى و اقل قيم يمكن ان تأخدها العلاقة

23 Multiplicity Indicators انواع العلاقات (طرق تمثيلها)
Exactly one 1 Zero or more (unlimited) * (0..*) One or more 1..* Zero or one (optional association) 0..1 Specified range 2..4

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

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

26


Download ppt "Class Diagrams."

Similar presentations


Ads by Google