Domain Model—Part 4A: Special associations - Composition.

Slides:



Advertisements
Similar presentations
DOMAIN MODEL SPECIAL ASSOCIATIONS – COMPOSITION AND INHERITANCE SYS466.
Advertisements

When is Orientated Programming NOT? Mike Fitzpatrick.
Object-Oriented Design – Key Concepts Version 1.1 of : added learning objectives CompSci 230 Software Construction.
 Kia Manoochehri ◦  Office Hours: 2:30-4:00 M/W ◦ HEC 308 (The Cave)
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
A Behavioral Pattern. Problem: Simple enough right? Object.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes Part 1.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Static vs. Dynamic Relationships CIS 480 System Analysis and Design.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation (Adapted) Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra,
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
PRJ566: PROJECT PLANNING AND MANAGEMENT Class Diagrams.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Unified Modeling Language
Object-Oriented Analysis and Design
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
Object Oriented Software Development
Introduction to UML Lian Yu Department of Computer Science and Engineering Arizona State University Tempe, AZ
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
1. 2 Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
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: 
DOMAIN MODE: ASSOCIATIONS, MULTIPLICITY AND ATTRIBUTE-TEXT NOTATION SYS466.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Unit 1 INTRODUCTION TO MODELING AND CLASS MODEL Ref : L7-UML.PDF.
1 Object-Oriented Programming Using C++ CLASS 5. 2 Object Composition Object composition occurs when a class contains an instance of another class. Creates.
Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation.
UML The Unified Modeling Language A Practical Introduction Al-Ayham Saleh Aleppo University
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Relationships between classes Using UML
Using COMET with Visio Visio UML Modeling. Creating a Drawing After opening Visio, you will see a list of templates available.
Design Jon Walker. More UML ● What is UML again?
Object Oriented Analysis: Associations. 2 Object Oriented Modeling BUAD/American University Class Relationships u Classes have relationships between each.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Database Design Some of these slides are derived from IBM/Rational slides from courses on UML and object-oriented design and analysis. Copyright to the.
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
Lab 5 CPIT 250 System Analysis and Design.
Ch- 8. Class Diagrams Class diagrams are the most common diagram found in modeling object- oriented systems. Class diagrams are important not only for.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
12 OBJECT-ORIENTED DESIGN CHAPTER
Chapter 4 Basic Object-Oriented Concepts. Chapter 4 Objectives Class vs. Object Attributes of a class Object relationships Class Methods (Operations)
GROUPING OBJECTS CITS1001. Lecture outline The ArrayList collection Process all items: the for-each loop 2.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Chapter 16 UML Class Diagrams.
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.
INFSY 535.  Small systems  Larger systems 1.Understand the program requirement- what 3. Write and test each part (unit testing) 4. Maintenance 2. Specify.
BTS430 Systems Analysis and Design using UML Domain Model—Part 2: Associations and Attributes.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 7, Feb 6/7, 2013.
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.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
UML Class Diagrams David Millard
Class Diagrams.
Creating and Using Classes
Object Oriented Analysis and Design
Class Diagrams Class diagram is basically a graphical representation of the static view of the system and represents different aspects of the application.
Class Diagram.
Object Oriented System Design Class Diagrams
Information System Design
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Domain Model—Part 4A: Special associations - Composition

ORDER contains many OrderLine objects. OrderLine objects have no “life” outside of order. OrderLine objects have no meaning outside of order. If you delete Order, all OrderLine objects will be gone. Order “encapsulates” OrderLine.

What does “Order ‘encapsulates’ OrderLine mean?  Order takes responsibility for creation of OrderLine objects  Order controls all communication to OrderLine objects  No other class knows that OrderLine exists  But OrderLine knows about other classes (e.g. Product)  OrderLine might not even appear in higher level models; only Order.

public class Order { private intorderID; private Customer customer; private List productOrderedSet; public Order(int newOrdID){ orderID = newOrdID; customer = new Customer(); productOrderedSet = new ArrayList (); } public Order(){ orderID = 0; customer = new Customer(); productOrderedSet = new ArrayList (); } public void addOrderLine(int inQty, Product inProd) { OrderLine newOrderLine = new OrderLine(inQty,inProd); productOrderedSet.add(newOrderLine); } public String getOrderedProduct(int orderLineInd) { return productOrderedSet.get(orderLineInd).getProductName(); } public int getOrderedQty(int orderLineInd) { return productOrderedSet.get(orderLineInd).getQty(); } public void addCustomer(Customer setCustomerTo) { this.customer=setCustomerTo; } public String getCustName() { return customer.getCustName(); } public int getOrderID() { return orderID; } The Order class (simplified version)

public class Order { private intorderID; private Customer customer; private List productOrderedSet; ………………………………………………………….. public void addOrderLine(int inQty, Product inProd) { OrderLine newOrderLine = new OrderLine(inQty,inProd); productOrderedSet.add(newOrderLine); } public String getOrderedProduct(int orderLineInd) { return productOrderedSet.get(orderLineInd).getProductName(); } public int getOrderedQty(int orderLineInd) { return productOrderedSet.get(orderLineInd).getQty(); } ……………………………………………………………… } Order is responsible for creating OrderLine objects and for getting OrderLine information

public class OrderLine { private int qtyOrdered; private Product product; public OrderLine(int qty,Product prod){ qtyOrdered = qty; this. product = prod; } public OrderLine(){ qtyOrdered = 0; product = new Product(); } public int getQty(){ return qtyOrdered; } public String getProductName(){ return product.getProductName(); } OrderLine knows about Product and can execute Product functions (e.g. product.GetProductName)

public class Product { private int productID; private String productName; public Product(int setToID,String setToName){ productID = setToID; productName = setToName; } public Product(){ } public String getProductName(){ return productName; } public int getProductID(){ return productID; } public void setProductName(String setToName){ productName = setToName; } public void setProductID(int setToID){ productID = setToID; } Product does not know anything about OrderLine; it does not know that OrderLine exists.

This strong relationship between Order and OrderLine is called a COMPOSITION and is shown using the “filled in diamond” symbol. Order is the container. OrderLine is the component or contained class.

 In order to specify composition we need to do two things:  First we use the aggregation symbol in Rose to create a relationship between Container (Order) and Component (OrderLine). We draw from Order to OrderLine.

 Then we select the “aggregate” relationship that we just drew and make it a composition by selecting “containment of OrderLine” and choosing “by value”.

The aggregation symbol on its own is used to denote a weaker relationship—weaker than composition but stronger than association. We will not be exploring this relationship in SYS466. It has limited use in modeling and has no definite “meaning” when translated to code.

 In SYS466 we will only be identifying composition in the “pattern” exemplified by Order/OrderLine, Sales/SaleLine, Bill/BillingItem, etc.  It is easier because those are the relationships that would naturally come from the Olympic Store’s business.

To denote a contained relationship that effectively hides a contained class from “outsiders”. Using a container can simplify a model; the container will be a proxy for all attributes and operations of the contained class. The contained class can be hidden. A composite relationship is reflected in code; if it is not specified then the code may not do what it is meant to. (e.g. the contained class may be visible to “outsiders”).