Relationships between classes Using UML

Slides:



Advertisements
Similar presentations
UML and Classes, Objects and Relationships [1]
Advertisements

©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System modeling 2.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
What is UML? A modeling language standardized by the OMG (Object Management Group), and widely used in OO analysis and design A modeling language is a.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
© Copyright Eliyahu Brutman Programming Techniques Course.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
PRJ566: PROJECT PLANNING AND MANAGEMENT Class Diagrams.
Unified Modeling Language
Object-Oriented Analysis and Design
 2008 Pearson Education, Inc. All rights reserved (Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements.
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
OBJECT ORIENTED PROGRAMMING LECTURE 12 Instructor: Rashi Garg Coordinator: Gaurav Saxena.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Dr. Salah Hammami KSU-CCIS-CS Ahmad Al-Rjoub CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science Chapter.
UML Diagrams: Class Diagrams The Static Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Programming in Java Unit 3. Learning outcome:  LO2:Be able to design Java solutions  LO3:Be able to implement Java solutions Assessment criteria: 
UML Class Diagrams and Caché CAMTA Meeting – 1 st December 2011 John Murray Senior Product Engineer.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
CET203 SOFTWARE DEVELOPMENT Session 1A Revision of Classes.
CS3773 Software Engineering Lecture 04 UML Class Diagram.
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
1 Advanced Software Architecture Muhammad Bilal Bashir PhD Scholar (Computer Science) Mohammad Ali Jinnah University.
Modeling system requirements. Purpose of Models Models help an analyst clarify and refine a design. Models help simplify the complexity of information.
Fall 2010 CS4310 Requirements Engineering A Brief Review of UML & OO Dr. Guoqiang Hu Department of Computer Science UTEP 1.
UML (U NIFIED M ODELING LANGUAGE ) Prepared by Miss Simab Shahid Lecturer computer Science and Software Engineering department, University.
1 Object Oriented Design and UML Class Relationships –Dependency –Aggregation –Interfaces –Inheritance Interfaces Reading for this Lecture: L&L 6.4 – 6.5.
1 Introduction to Classes and Objects Chapter 3 Introduction to Classes and Objects Chapter 3.
PROG Object Oriented Programming II With Java PROG Object Oriented Programming II With Java Class Relationships.
UML The Unified Modeling Language A Practical Introduction Al-Ayham Saleh Aleppo University
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,
Design Model Lecture p6 T120B pavasario sem.
Object Oriented Analysis: Associations. 2 Object Oriented Modeling BUAD/American University Class Relationships u Classes have relationships between each.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Object Oriented Analysis and Design Class and Object Diagrams.
Introduction to UML CS A470. What is UML? Unified Modeling Language –OMG Standard, Object Management Group –Based on work from Booch, Rumbaugh, Jacobson.
Lab 5 CPIT 250 System Analysis and Design.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Class Diagram Chapter 21 Applying UML and Patterns Craig Larman.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Class Diagram Lecture # 1. Class diagram A Class Diagram is a diagram describing the structure of a system shows the system's classes Attributes operations.
Unit 1 - Introducing Abstract Data Type (ADT) Part 1.
1 IS 0020 Program Design and Software Tools Unified Modeling Language Lecture 13 April 13, 2005.
Software Modelling Class Diagram. Class Diagrams The main building block in object oriented modeling They are used both for general conceptual modeling.
 2007 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CS 350 – Software Design UML – The Unified Modeling Language – Chapter 2 The Unified Modeling Language is a visual language used to create models of programs.
Data Modeling Using the Entity- Relationship (ER) Model
Class Relationships in C++
Unified Modeling Language (UML)
UML Diagrams: Class Diagrams The Static Analysis Model
Unified Modeling Language
Visit for more Learning Resources
Introduction to Unified Modeling Language (UML)
Chapter 18: Refining Analysis Relationships
Software Engineering Lecture #11.
تحليل انظمة و تصميمها الوحدة الخامسة أ.محمد زكي شبير.
UML Class Example Sales - name: string - monthlyProfit : double[] public class Sales{ private String name; private double[] monthlyProfit; public.
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Class Diagrams Class diagram is basically a graphical representation of the static view of the system and represents different aspects of the application.
Information System Design
UML  UML stands for Unified Modeling Language. It is a standard which is mainly used for creating object- oriented, meaningful documentation models for.
Presentation transcript:

Relationships between classes Using UML Chapter 2 Relationships between classes Using UML CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science Ahmad Al_rjoub ahmadrj@ksu.edu.sa

Objectives: What is UML? ``UML is a standard language for writing software blueprints. The UML may be used to visualize, specify, construct and document the artifacts of a software intensive system'' Defined semantics for each of the graphical symbols Allows for unambiguous specification and for inspection of requirements and designs Allows tools to directly generate code from diagrams - but programmers still has to do some work Provides documentation of products, so allowing auditing and facilitating management

OUTLINE UML Object Models: Classes Association Composition Aggregation Examples

1. UML Object Models: Classes Class name Class Name Attributes Methods Class Name Should be descriptive of the class and capitalized in the first letter Attributes The named properties of the class. Can be typed, possibly with default values Methods Services offered by the class. Methods can be typed e.g. parameter types and return types specified.

Association, Aggregation, and Composition 2. UML Object Models: Association, Aggregation, and Composition Associations UML diagrams show a collection of named boxes - indicating classes or types of object. The boxes have lines connecting them called links. Each link is called an association and should model some relationship or connection between the classes. Associations also play roles in classes that are often given special names. Company name: String contactPerson: Client employees: Client[] Example: Classes can contain references to each other.  The Company class has two attributes that reference the Client class.

Association, Aggregation, and Composition UML Object Models: Association, Aggregation, and Composition Associations Although this is perfectly correct, it is sometimes more expressive to show the attributes as associations. Client lastName: String firstName: String email: String Company name: String contactPerson 1 1 employees 1 0..*

Association, Aggregation, and Composition UML Object Models: Association, Aggregation, and Composition Associations The above two associations have the same meaning as the attributes in the old version of the Contact class.  The first association (the top one) represents the old contactPerson attribute.  There is one contact person in a single Company.  The multiplicity of the association is one to one meaning that for every Companythere is one and only one contactPerson and for each contactPerson there is one Company. 

Association, Aggregation, and Composition UML Object Models: Association, Aggregation, and Composition Associations Client lastName: String firstName: String email: String Company name: String contactPerson 1 1 employees 1 0..* The first association (the top one) represents the old contactPerson attribute.  There is one contact person in a single Company. The multiplicity of the association is one to one meaning that for every Companythere is one and only one contactPerson and for each contactPerson there is one Company.  In the bottom association there are zero or many employees for each company. 

Association, Aggregation, and Composition UML Object Models: Association, Aggregation, and Composition Associations Multiplicities can be anything you specify.  Some examples are shown: zero 1 one 1..* one or many 1..2, 10..* one, two or ten and above but not three through nine

3. UML Object Models: Aggregation, and Composition UML provides several notations that can express the physical construction of a class. The filled in diamond is often used when a class contain other objects within them as parts or components. The composition association is represented by the solid diamond. Here are two examples: Period is composed of Time and Day.  Period t: Time [2] d: Day [5] Time Day t 2 d 5 We can use the dark diamond to indicate that the class possesses the components in the sense of controlling whether they exist of not. The filled in diamond indicates that the deletion of an object may delete its components as well.

4. UML Object Models: Aggregation, and Composition We can also show that a class has some parts and yet they have an independent existence. Example: In the computer world a page on the world Wide Web can use a hypertext reference to point to another resource -- deleting the page does not effect the other page. This association is called aggregation. is represented by the hollow diamond. Here is an example showing that a Restaurant will have a number of clients who are People and the the clients exist whether or not they are clients of the Restaurant:

UML Object Models: Aggregation, and Composition Product 1..* 1 PRP PDP ProductGroup ProductGroup(in size:int, …) addPrd(in P: Product) PurchaseOrder PurchaseOrder(in size:int, …) Product() Product(in P:Product) Example 1: ProductGroup is composed of Products.  This means that if a ProductGroup is destroyed, the Products within the group are destroyed as well.  PurchaseOrder is an aggregate of Products.  If a PurchaseOrder is destroyed, the Products still exist. If you have trouble remembering the difference between composition and aggregation, just think of the alphabet.  Composition means destroy and the letters 'c' and 'd' are next to each other.

UML Object Models: Aggregation, and Composition How to Implement Aggregation? How to Implement Composition? public class PurchaseOrder { private Product PRP []; private int nprp; // number of current product in the array. ….. public PurchaseOrder (int size, …) PRP = new Product[size]; nprp=0; …. }  …… public class ProductGroup { private Product PDP []; private int npdp; // number of current product in the array. ….. public ProductGroup (int size, …) PDP = new Product[size]; npdp=0; …. }  ……

UML Object Models: Aggregation, and Composition Aggregation: How to add a new product Composition: How to add a new product public class PurchaseOrder { private Product PRP []; private int nprp; // number of current product in the array. ….. public void addPrd (Product P) PRP[nprp] = P; nprp++; }  …… public class ProductGroup { private Product PDP []; private int npdp; // number of current product in the array. ….. public void addPrd (Product P) PDP[npdp] = new Product(P); nprp++; }  ……

UML Object Models: Aggregation, and Composition Example 2:

UML Object Models: Aggregation, and Composition Example 2: The following Java code shows just how the links between the different objects can be implemented in Java. Note that this code just shows the links. It does not show constructors, or any other methods what would be required to actually use these objects. /* * Section.java - */ public class Section { private String sectionName; private int capacity; private int currentNbStudents; private Student[ ] stud;  …. public void addStudent(Student s) stud[currentNbStudents]=s; currentNbStudents ++; } // ... /* * Student.java - */ public class Student { private String name; private String id;   public void copyStudent(Student st) name= st.name; id= st.id ; } // ...

UML Object Models: Aggregation, and Composition Example 2: /* * Teacher.java - */ public class Teacher { private String teacherName; private String Id; private Section[3] sect; // ...   } /* * Teacher.java - */ public class Department { private String departName; private Student[ ] stud; private Course[ ] csc; private Teacher[ ] teach;   // ... } /* * Course.java - */ public class Course { private String courseName; private int nbSection; private Section[ ] sect; // ...   }

UML Object Models: Aggregation, and Composition Example 3: +Car(in n : string, in d : string, in s : int, in y : int, in size : int) +display() +isFull() : bool +copyCar(in ca : Car) +addElement(in el : CarElements) : bool +PriceCar() : double +...........(in .........) -seatNb : int -year : int -ncel : int Car +CarElements(in c : string, in p : double) +CarElement(in E : CarElements) +.....(in .........) -code : string -price : double CarElements 1 * +KsuCars(in size : int) +isEmpty() : bool +searchCar(in ce : string) : int +getCar(in nm : string) : Car +AveragePrice(in y : int) : double +.........(in .......) +remove(in s : string) : bool -nbc : int KsuCars - name : string -id : string

Description of the different classes: Question: Implement all the classes with all their methods using the following descriptions. Description of the different classes:   Class CarElements: ü      The method display () displays the code and the price. ü      + …….. (in ……..) : if you need an other methods in this class you can add it. You can’t add another constructor. Class Car: ·        name id seatNb : Number of seats ·        year : Production year of car ·        ncel : number of CarElements object currently in an object of the class Car. ·        And other attribute(s) deduced from the UML diagram. ü      display (): Displays all the attributes of an object Car. ü      addElement (CarElements el): This method receives a CarElements object and adds it to the Car object. ü      priceCar(): Returns the sum of the CarElements price in an object of the class Car. + …….. (in ……..) : if you need an other methods in this class you can add it. Class KsuCars: ·        nbc : number of Car currently in an object of the class KsuCar. ·        And other attribute(s) deduced from the UML diagram. ü      display (): Displays all the attributes of an object KsuCars. ü      search (String ce): This method receives a String representing the name of a Car object and returns the array index of the car object. ü      getCar (String nm): This method receives a String representing the id of a Car object and returns the Car object if it’s exist. ü      removeCar (String s): Removes a Car according to its name. It will return a value true if the operation has been completed successfully, or false if not. ü      AveragePrice(int y): Calculates the average price of all car in an object of class KsuCars that produced after the year y. ü      + …….. (in ……..) : if you need an other methods in this class you can add it.