1 / 22

UML Class & Object Diagram II

UML Class & Object Diagram II. E mployee. Company. add(e : Employee). Dependency:. A relationship between two modeling elements indicates that a change in the destination may effect the source. Example – dependency between classes: Company is dependent on Employee.

micaelal
Télécharger la présentation

UML Class & Object Diagram II

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. UML Class & Object DiagramII

  2. Employee Company add(e : Employee) Dependency: A relationship between two modeling elements indicates that a change in the destination may effect the source. Example – dependency between classes: Company is dependent on Employee The operation add has an employee object as argument: A change in Employee may inflict a change of the add operation.

  3. Dependency on Package Diagram From MagicDraw

  4. class name Point visibility attributescompartment - x : int - y : int + getX() : int operationscompartment + setX(aX : int) : void + getY() : int operationsignature + setY(aY : int) : void Class: Describes a Set of Objects Modelling tool:Rational Rose 2000 Additional compartments may be supplied, e.g., a constraints compartment.

  5. Attribute/Property(Implemented as Field in Java, data member in C++) Description of a named slot of a specified type in a class. Each object of the class separately holds a value of the type. <<stereotype>>opt / optvisibilityopt name multiplicityopt : typeopt … Used if the value of the attribute can be derived from other information. - (private) only the class can see this attribute # (protected) only the class and all of its subclasses + (public) all classes that can see the class can also see the attribute ~ (package) only classes in the package can see the attribute E.g. <<unique>>

  6. Attribute continues Example:Tagged value e.g.Author = Kari … name multiplicityopt : typeopt = initial-valueopt {property-string}opt Example: email[1..*] : String Indicating one or more email addresses. (If no email is present you will still have the empty string (””).)If email[0..*] : String is specified, then email can be null.

  7. OrdinaryAssocaitionWith Navigability: If you have a Quiz-object, the associated Question-objects can be directly reach from the Quiz-object.I.e., there will be a reference to each Question-object inside the Quiz-object but not the other way around. questions Quiz Question base class 1..* * association with navigation One possible mapping to Java classQuiz{ // A list of questions Question [] questions; .... } class Question { // no reference to Quiz .... }

  8. A Class Diagram - Mapping to Java responsible for * 1 Course Person -name : String -description : String #name : String #imail : String #homePage : String tech. responsible for 1 * 1 * * StudentCourseProfile 1 Student -finished : boolean publicclass Person { protected String name; protected String imail; protected String homePage; // // Navigation protected Course[] responsibleFor; protected Course[] techResponsibleFor; } publicclass Student extends Person { // // Navigation public StudentCourseProfile[] studentCourseProfile; }

  9. Generalization: A relationship between a more general element and a more specific one. For example: A bird is also an animal.(Generalization is not an association, but it do relate objects in regard to classification.) Animal A bird is a specialization of an animal. It inherits the structure and behaviour of Animal. Bird Eagle Generalization is a transitive relation!

  10. The class Snake realises (implements) the interface Movable. Snake move(x,y) Realization: UML: ”A semantic relationships between classifiers, in which one classifier specifies a contract that another classifier guarantees to carry out”. <<interface>> Movable Snake inherits the behaviour specified by the operations of Movable (as an interface Movable has no internal structure). move(x,y)

  11. Class DiagramsDefinesGraph Structures

  12. Association • Describes a set of links between objects, indicating some sort of connection between objects of the involved classes. • Example: A person may have friends. :friendship p2:Person p1:Person f1 * friendship :friendship * Person :friendship f2 :friendship p3:Person p4:Person :friendship possible graph structure, i.e., objects with links

  13. f1 * friendship * Person f2 defines an infinite set of graphs where the nodesare called Person and the edges are called friendship end1 edge * * Node end2 “ordinary graph” with “ordinary names” What if we need to attach some information to the edges?

  14. Different Types Associations In UML class diagrams you can distinguish between: • Ordinary Association • Aggregation (weak aggregation/shared association) • Composition(strong aggregation)

  15. Aggregation/Composition • Indicates that one object contains objects of a given type, i.e., a whole/part relationship. • No cycles are allowed. • A transitive relation. the part aggregation the whole using aggregation allows a department to be shared among companies Company Department * 1..* Composition aggregation (strong aggregation) Company Department 1..* 1 Must be 1 or 0..1 No limitations on this multiplicity

  16. Aggregation is a weaker form of aggregation than composition. A part instance might be included in more than one aggregation at a time, which is not allowed for composition. Company Department Employee 1..* * 1 1..* a department can only belong to one company at a time an employee can belong to severaldepartments at a time

  17. Composition defines a directed tree and an aggregation defines a directed graph (without cycles). • Using these properties to define a directed graph and directed tree: DirectedTree DirectedAcyclicGraph 0..1 0..1 topRoot 0..1 * * predecessor root Node Node 0..1 child * * successor  edge edge

  18. DirectedAcyclicGraph 0..1 * * predecessor Node * successor  :Directed-AcyclicGraph edge Do you see errors? :Node :Node :Node :Node :Node :Node :Node :Node

  19. DirectedAcyclicGraph 0..1 * * predecessor Node * successor  :Directed-AcyclickGraph edge Do you see errors? :Node :Node :Node :Node :Node :Node :Node :Node

  20. DirectedTree 0..1 topRoot 0..1 root Node 0..1 child * :DirectedTree Do you see errors? edge :Node :Node :Node :Node :Node :Node :Node :Node

  21. DirectedTree 0..1 topRoot 0..1 1 root Node child * edge :DirectedTree Do you see errors? :Node :Node :Node :Node :Node :Node :Node :Node

  22. Deletion Characteristics UML 2.1 specification: “… If a composite is deleted, all of its parts are normally deleted with it… deleting an element in one part of the graph will also result in the deletion of all elements of the subgraph below that element.”

More Related