1 / 26

Class Diagrams

Class Diagrams. 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 و كل من المتغيرات و الدوال الموجودة بها و العلاقة بينها

mccurley
Download Presentation

Class Diagrams

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 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 للاجزاء الاخرى من النظام و يتم اعطاء هذه القيمة للمتغيرات و الدوال على حد سوا

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

  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. Borrower 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 Book currBorr bk[]

  9. Association(Java implementation) public class Borrower { Book bk[]; intnumBooks; … 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; } }

  10. Car 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 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. 2 Line Point 3..* Polygon Composition • A strong form of aggregation: • هي علاقة اقوى من ال 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 • في هذه العلاقة وجود الجزء او عدمه يعتمد على الكل حيث يتحكم في إنشاء و حذف الاجزاء

  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 • 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. Bank processTransactions () Parser getTransaction() uses 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

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

  19. 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 parts 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 • انواع العلاقات (طرق تمثيلها)

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

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

More Related