Скачать презентацию Class Diagrams CLASS DIAGRAM A class diagram Скачать презентацию Class Diagrams CLASS DIAGRAM A class diagram

1b4cf7ad209c8dc10901f47ee7fd591a.ppt

  • Количество слайдов: 26

Class Diagrams Class Diagrams

CLASS DIAGRAM *A class diagram defines the classes of objects in the system, the 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. ﻫﻮ ﺍﺣﺪ ﻃﺮﻕ ﺍﻟﺘﻤﺜﻴﻞ ﺍﻟﺜﺎﺑﺘﻪ ﺍﻟﺘﻲ ﺗﻌﺮﺽ ﻣﺠﻤﻮﻋﻪ ﺍﻟﻤﺘﻐﻴﺮﺍﺕ ﻭ ﺍﻟﺪﻭﺍﻝ ﺩﻭﻥ ﻭﺻﻒ ﻛﻴﻔﻴﺔ ﺍﻧﺠﺎﺯ ﻣﻬﻤﻪ ﻣﺤﺪﺩﻩ

Essential Elements of a UML Class Diagram : ﺍﻟﻤﻜﻮﻧﺎﺕ ﺍﻻﺳﺎﺳﻴﺔ ﻟﻬﺬﺍ ﺍﻟﻨﻈﺎﻡ ﻫﻲ Class. Essential Elements of a UML Class Diagram : ﺍﻟﻤﻜﻮﻧﺎﺕ ﺍﻻﺳﺎﺳﻴﺔ ﻟﻬﺬﺍ ﺍﻟﻨﻈﺎﻡ ﻫﻲ Class. Attributes. Operations. Relationships. ◦ Associations. Aggregation & Composition. ◦ Generalization. ◦ Dependency.

Classes A class is the description of a set of objects having similar “attributes”, Classes A class is the description of a set of objects having similar “attributes”, “operations”, relationships and behavior. ( ﻟﻬﺎ ﻧﻔﺲ ﺍﻟﻤﺘﻐﻴﺮﺍﺕ ﻭ objects) : ﻫﻮ ﻭﺻﻒ ﻟﻤﺠﻤﻮﻋﻪ ﺍﻟﺤﺎﻻﺕ class ﺍﻝ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﻟﻌﻼﻗﺎﺕ ﻓﻴﻤﺎ ﺑﻴﻨﻬﺎ Window Size: size Visibility: boolean Display() hide. I() Class Name Attributes Operation s Drink Name: String Price: Double Check. Drink()

Modeling Visibility: An enumeration whose value (public, protected, package, or private) denotes how the Modeling 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 ﻟﺘﻮﺿﻴﺢ ﻛﻴﻔﻴﺔ ﻇﻬﻮﺭ ﻣﻜﻮﻧﺎﺕ ﺍﻝ ﻫﺬﻩ ﺍﻟﻘﻴﻤﺔ ﻟﻠﻤﺘﻐﻴﺮﺍﺕ ﻭ ﺍﻟﺪﻭﺍﻝ ﻋﻠﻰ ﺣﺪ ﺳﻮﺍ Visibility Level Private Package Public Protected Symbol ~ + #

Elements of class diagram… Class name compartment Attributes compartment Operations compartment Client - company. Elements of class diagram… Class name compartment Attributes compartment Operations compartment Client - company. Address - company. Email - company. Fax + company. Name private public # company. Telephone + get. Client. Info( ) - update. Client. Info( ) protected

Associations A semantic relationship between two or more classes that specifies connections among their 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”.

Associations (cont. ) An association between two classes indicates that objects at one end 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 ﻫﺬﻩ ﺍﻟﻌﻼﻗﺔ ﺑﻴﻦ ﺍﻝ ﺍﻟﺘﻌﺮﻑ ﻋﻠﻲ ﻣﺘﻐﻴﺮﺍﺕ ﻭ ﺩﻭﺍﻝ ﺍﻟﺜﺎﻧﻲ ﻭ ﻳﺴﺘﻄﻴﻊ ﺍﺭﺳﺎﻝ ﻗﻴﻢ ﻟﻪ Borrower 1 curr. Borr 3 bk[] Book

Association (Java implementation) public class Borrower { Book bk[]; int num. Books; … public Association (Java implementation) public class Borrower { Book bk[]; int num. Books; … public Borrower() { num. Books = 0; bk = new Book[3]; } // methods that update bk public void borrow. Book( Book b ) { bk[num. Books] = b; num. Books++; b. set. Borrower( this ); } } public class Book { Borrower curr. Borr; public void set. Borrower( Borrower bw ) { curr. Borr = bw; } }

Aggregation A special form of association that models a whole-part relationship between an aggregate 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 wheels Whole Wheel Part

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

Composition A strong form of aggregation: aggregation ﻫﻲ ﻋﻼﻗﺔ ﺍﻗﻮﻯ ﻣﻦ ﺍﻝ ◦ The 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 ﻓﻲ ﻫﺬﻩ ﺍﻟﻌﻼﻗﺔ ﻭﺟﻮﺩ ﺍﻟﺠﺰﺀ ﺍﻭ ﻋﺪﻣﻪ ﻳﻌﺘﻤﺪ ﻋﻠﻰ ﺍﻟﻜﻞ ﺣﻴﺚ ﻳﺘﺤﻜﻢ ﻓﻲ ﺇﻧﺸﺎﺀ ﻭ ﺣﺬﻑ ﺍﻻﺟﺰﺍﺀ 2 Line Polygon Point 3. . *

Composition (Java implementations) public class Car { private Wheel wheels[]; . . . public 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(); … }. . . }

Generalization Indicates that objects of the specialized class (subclass) are substitutable for objects of Generalization Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class) ◦ “is kind of” relationship super-class ﻳﻤﻜﻦ ﺍﻥ ﺗﺤﻞ ﻣﺤﻞ ﺍﻝ subclass ◦ ﻫﺬﻩ ﺍﻟﻌﻼﻗﺔ ﺗﺒﻴﻦ ﺍﻥ An abstract class Shape Super Class Circle Sub Class Generalization relationship

Generalization A sub-class inherits from its super-class: : ﻳﺮﺙ ﺍﻟﺠﺰﺀ ﺍﻟﺨﺼﺎﺋﺺ ﺍﻟﺘﺎﻟﻴﺔ ◦ Attributes. 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.

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

Dependency A dependency indicates a semantic relation between two or more classes in which 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 Bank process. Transactions () uses Parser get. Transaction()

Dependency (Java implementation) public class Bank { … public void process. Transactions() { // Dependency (Java implementation) public class Bank { … public void process. Transactions() { // Parser p is a local variable … Parser p = new Parser(…); … p. get. Transaction(); … }

Realization A realization relationship indicates that one class implements a behavior specified by another 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. Linked. List <> List Linked. List

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

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

 Multiplicity ◦ The number of instances of the class, next to which the 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. ◦ ﺗﻮﺿﺢ ﺍﻋﻠﻰ ﻭ ﺍﻗﻞ ﻗﻴﻢ ﻳﻤﻜﻦ ﺍﻥ ﺗﺄﺨﺪﻫﺎ ﺍﻟﻌﻼﻗﺔ

◦ Multiplicity Indicators ( ◦ ﺍﻧﻮﺍﻉ ﺍﻟﻌﻼﻗﺎﺕ )ﻃﺮﻕ ﺗﻤﺜﻴﻠﻬﺎ Exactly one Zero or more ◦ Multiplicity Indicators ( ◦ ﺍﻧﻮﺍﻉ ﺍﻟﻌﻼﻗﺎﺕ )ﻃﺮﻕ ﺗﻤﺜﻴﻠﻬﺎ Exactly one Zero or more (unlimited) 1 * (0. . *) One or more 1. . * Zero or one (optional association) 0. . 1 Specified range 2. . 4

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

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