Object Oriented Software Development

Slides:



Advertisements
Similar presentations
CIT731: Database Development Object Oriented Modeling (OOM)
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Object-Oriented Analysis and Design
Chapter 15: System Modeling with UML
Introduction To System Analysis and Design
Essentials of class models. 2 A very simple class model In UML, a class is shown in a class diagram as a rectangle giving its name.
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.
Class Diagram & Object Diagram
Lecture a: Additional UML Models: Package, Activity, Deployment Lecture b: Generalization, Aggregation and Additional Domain Model Notation Copyright W.
Sharif University of Technology1 Design and Use-case Realization Software Engineering Laboratory Fall 2006.
PRJ566: PROJECT PLANNING AND MANAGEMENT Class Diagrams.
Designing with Interaction and Design Class Diagrams Chapters 15 & 16 Applying UML and Patterns Craig Larman With some ideas from students in George Blank’s.
UML Class Diagrams: Basic Concepts. Objects –The purpose of class modeling is to describe objects. –An object is a concept, abstraction or thing that.
Unified Modeling Language
The Unified Modeling Language (UML) Class Diagrams.
Object-Oriented Analysis and Design
Object-Oriented Design. From Analysis to Design Analysis Artifacts –Essential use cases What are the problem domain processes? –Conceptual Model What.
UML for Java Programmers Object Mentor, Inc. Copyright  by Object Mentor, Inc All Rights Reserved
Association & Aggregation Lecture-9. Vehicle Car Tyre Engine Bus Passenger.
Object Oriented Software Development
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.
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
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: 
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 9: Interaction.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
Systems Analysis and Design in a Changing World, 3rd Edition
Chapter 16 Applying UML and Patterns Craig Larman
1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.
UML for OOADStefan Kluth 1 2UML for OOAD 2.1What is UML? 2.2Classes in UML 2.3Relations in UML 2.4Static and Dynamic Design with UML.
NJIT UML Class Diagrams Chapter 16 Applying UML and Patterns Craig Larman.
Introduction to Unified Modeling Language (UML) By Rick Mercer with help from The Unified Modeling Language User Guide, Grady Booch, James Rumbaugh, Ivar.
Design Jon Walker. More UML ● What is UML again?
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object Oriented Software Development
Design Model Lecture p6 T120B pavasario sem.
Karolina Muszyńska Based on: S. Wrycza, B. Marcinkowski, K. Wyrzykowski „Język UML 2.0 w modelowaniu SI”
M1G Introduction to Programming 2 5. Completing the program.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
UML Part 1: Class Diagrams. Introduction UML stands for Unified Modeling Language. It represents a unification of the concepts and notations presented.
Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole.
INFO 620Lecture #71 Information Systems Analysis and Design Design Class Diagrams and others INFO 620 Glenn Booker.
Object-Oriented Analysis and Design Use cases Finding classes Collaboration and Sequence diagrams Associations between classes.
Chapter 3: Introducing the UML
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
UML Fundamental Elements. Structural Elements Represent abstractions in our system. Elements that encapsulate the system's set of behaviors. Structural.
Introduction to Unified Modeling Language (UML) By Rick Mercer with help from The Unified Modeling Language User Guide, Grady Booch, James Rumbaugh, Ivar.
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
Modeling with UML – Class Diagrams
Analysis Classes Unit 5.
Unified Modeling Language
Course Outcomes of Object Oriented Modeling Design (17630,C604)
Standard UML: Communication and Dynamic Behavior
Unified Modeling Language
Introduction to Unified Modeling Language (UML)
Object-Orientated Programming
UML Class Diagrams: Basic Concepts
Unified Modeling Language
IMAT5205 Systems Analysis and Design
Analysis models and design models
Software Design Lecture : 15.
Review CSE116 2/21/2019 B.Ramamurthy.
Use Case Analysis – continued
Object Oriented System Design Class Diagrams
Uml diagrams In ooad.
UML  UML stands for Unified Modeling Language. It is a standard which is mainly used for creating object- oriented, meaningful documentation models for.
ITEC324 Principle of CS III
Presentation transcript:

Object Oriented Software Development 7. Implementing a model

UML models UML may be used to visualise, specify, construct and document the artefacts of a software system Part of a software development method To produce a working application the artefacts in the model must be implemented using development tools, languages and frameworks Object Oriented Software Development 7. Implementing a model 2

Implementing a model We will use Visual Studio, C# and the .NET framework to begin the implementation of a UML model Based on examples from Software Modelling Analysis and Design 1 That module and this one represent two closely related aspects of the same process Object Oriented Software Development 7. Implementing a model 3

UML diagrams and C# code Class Diagram – a C# application is constructed as classes, which generally correspond to classes in the class diagram Sequence/Collaboration Diagrams – these describe the messages which pass between objects, and relate to method calls in C# code Object Diagram – represents the objects which exist as the program runs Use Case Flow of Events/Activity Diagrams – describe sequences of events and workflows which must be implemented in C# code Object Oriented Software Development 7. Implementing a model 4

Example – order system In the system, an order consists of a number of order lines An order line specifies a single product and the quantity of that product ordered Each order is associated with a customer, who has a discount level which is applied to all his or her orders Sample code in OrderSystem project Object Oriented Software Development 7. Implementing a model 5

Use case – calculate order price We will look at the use case, the classes involved in it and the sequence diagram for it Use Case Description Calculates the total price of a single order including the customer’s discount Use Case Flow of events Calculate the price of each order line as (product price) x (quantity) and add to total Apply the customer’s discount to the total and calculate the final price Object Oriented Software Development 7. Implementing a model 6

Class diagram customer can be associated with many orders orderline only exists as part of an order - composition order line contains one product only Object Oriented Software Development 7. Implementing a model 7

Sequence diagram collaborates with other objects to do so responsibility for calculating its price belongs to order Object Oriented Software Development 7. Implementing a model 8

Create classes using class diagram Create a new C# class for each class in the diagram Declare instance variables based on the attributes in the diagram Define (empty) methods based on the operations in the diagram Methods which simply access instance variables (e.g. GetDiscount) can be implemented in C# as properties Object Oriented Software Development 7. Implementing a model 9

Create classes using class diagram Consider whether properties should be read-write or read-only Define constructor to set values of instance variables Object Oriented Software Development 7. Implementing a model 10

Implement relationships Add code to implement relationships between classes shown in the diagram May need to refine model to clarify the meaning of the relationship in some cases Purpose of relationship is to allow objects to collaborate, so sequence diagram may help clarification by showing what collaborations are needed Object Oriented Software Development 7. Implementing a model 11

OrderLine – Product association OrderLine is associated with a single product OrderLine sends a message to Product Product does not need to send message to OrderLine, so doesn’t need an OrderLine reference Association is navigable in one direction only, OrderLine to Product Object Oriented Software Development 7. Implementing a model 12

OrderLine-Product implementation Implement this with an instance variable in OrderLine of type Product Product has no reference to OrderLine C# implementation option – create LinePrice property instead of a GetLinePrice method Cleaner syntax but no difference conceptually – accessing a property is a message, just like a method call Object Oriented Software Development 7. Implementing a model 13

OrderLine-Product Note – when constructor would only set properties, can omit it and create objects with object initialiser syntax in C# sends message to product object to ask for its price Object Oriented Software Development 7. Implementing a model 14

Coding patterns This is an example of a one-to-one “has-a” association OrderLine has-a Product Common type of association, usually implemented using the same coding pattern One class has an instance variable whose type is the name of the other class Can also provide a property or accessor method for this instance variable if required Object Oriented Software Development 7. Implementing a model 15

Coding patterns A pattern is a general reusable solution to a common problem Patterns can be applied to many aspects of software design and programming, from loops to complex groups of collaborating classes Here we are using patterns for relationships between two classes (binary relationship coding patterns) Object Oriented Software Development 7. Implementing a model 16

Coding patterns The coding pattern for a relationship includes: Implementation The code artefact without which the relationship does not exist Helpers Properties and methods which may be required to make use of the relationship in particular situations Object Oriented Software Development 7. Implementing a model 17

Coding pattern: one-to-one “has-a” association Implementation Instance variable in one class whose type is the name of the other class Helpers Property in the first class which can be used to get or set the associated object Object Oriented Software Development 7. Implementing a model 18

Order – OrderLine association Order is associated with many OrderLines Order “has-a” set of OrderLines OrderLine only exists as part of an order – composition This is a whole-part relationship Order sends a message to OrderLine (GetLinePrice) Association is navigable in one direction only, Order to OrderLine Object Oriented Software Development 7. Implementing a model 19

Order – OrderLine implementation Implement this with an instance variable in Order which is a collection of type OrderLine OrderLine has no reference to Order Order will call GetLinePrice method of each of its OrderLines C# implementation option – what kind of collection should we use? No need to search, will only add to end of collection, best option is List<OrderLine> Object Oriented Software Development 7. Implementing a model 20

Order - OrderLine sends message to OrderLine object to get its line price Object Oriented Software Development 7. Implementing a model 21

Order – OrderLine helper method Need a method which can add a new OrderLine to an Order Composition – the new OrderLine object is created within this method OrderLine is added to List using its Add method Object Oriented Software Development 7. Implementing a model 22

Coding pattern: one-to-many “has-a” association Implementation Instance variable in one class whose type is a collection which holds instances of the other class Helpers Method to add objects to the collection (will create objects if the association is composition) Method to remove an object Method to return a specific object Method to return the whole collection Only need to implement helper(s) as needed Object Oriented Software Development 7. Implementing a model 23

Coding pattern example code CodingPatterns solution OneToManyCompositionPattern project Demonstrates pattern with a full set of helpers Object Oriented Software Development 7. Implementing a model 24

Order-Customer association Customer can have many Orders Customer “has-a” set of Orders But Order is not part of a Customer Customer does not create Order Association or aggregation, not composition Order is associated with one Customer Order “has-a” Customer Object Oriented Software Development 7. Implementing a model 25

Order-Customer association In this use case, Order needs to send message to Customer Order class needs reference to Customer object Order is associated with one Customer Order “has-a” Customer Association or aggregation So the relationship between Order and Customer is navigable in both directions Object Oriented Software Development 7. Implementing a model 26

Order-Customer association Actually, this use case does not require any messages from Customer to Order Don’t strictly need to implement association in that direction Implementing it here because it is likely that other use cases will require it e.g. Show orders for a customer Object Oriented Software Development 7. Implementing a model 27

Aggregation and association Implies ownership Whole-part, or “has-a” relationship Part may be shared with other Wholes, unlike composition Association No implication of ownership “uses-a” relationship Difference in meaning - makes little difference to code Object Oriented Software Development 7. Implementing a model 28

Aggregation and association “Few things in the UML cause more consternation than aggregation and composition, in particular how they vary from regular association...” Martin Fowler, 2003 See link below for full quote: http://www.martinfowler.com/bliki/AggregationAndComposition.html Object Oriented Software Development 7. Implementing a model 29

Class diagram with navigabilities Object Oriented Software Development 7. Implementing a model 30

Order-Customer implementation Need an instance variable in Customer which is a collection of type Order Need an instance variable in Order which is a reference to a Customer Order will call GetDiscount method of its Customer Need some code to make relationship consistent Order object should be part of the orders collection belonging to its associated Customer Object Oriented Software Development 7. Implementing a model 31

Order-Customer implementation implemented as a Dictionary for fast searching Object Oriented Software Development 7. Implementing a model 32

Order-Customer consistency constructor of Order when you create an order, you specify the customer it’s for, and add it to that customer’s orders method in Customer Object Oriented Software Development 7. Implementing a model 33

Creating objects create Customer object create Order object Object Oriented Software Development 7. Implementing a model 34

Coding pattern: one-to-many bidirectional association Implementation Implement as a one-to-many and a one-to-one in opposite directions Code in constructor of one class ensures consistency Helpers Same as one-to-many Remove method may need additional code to deal with consistency Object Oriented Software Development 7. Implementing a model 35

Coding pattern example code OneToManyAssociationPattern project OneToManyBidirectionalPattern project Demonstrate patterns with a full set of helpers Object Oriented Software Development 7. Implementing a model 36

Order – Product association We didn’t show an association on the class diagram between Order and Product No message passed between Order and Product in sequence diagram But there is a relationship Order “uses-a” Product to create an OrderLine Simple association Sometimes modelled as a dependency Object Oriented Software Development 7. Implementing a model 37

Order – Product association AddOrderLine method in order has a parameter of type Product Temporary association – only exists while this method runs Sets up permanent association between Product and OrderLine Object Oriented Software Development 7. Implementing a model 38

Class diagram with Order-Product Object Oriented Software Development 7. Implementing a model 39

Coding pattern: simple association Implementation One class has a reference to instance(s) of the other in one of the following places: Method parameter Method return value Local variable Object Oriented Software Development 7. Implementing a model 40

Coding pattern example code SimpleAssociationPattern project Object Oriented Software Development 7. Implementing a model 41

Other relationship examples These examples and patterns don’t capture all possible types of relationship Provide examples on which to base solutions to real problems Object oriented systems model the real world, and reality can be complicated! Object Oriented Software Development 7. Implementing a model 42

What’s next? We will go on to look at some practical issues which are important in developing robust programs, including handling error situations with exceptions, debugging and testing Object Oriented Software Development 7. Implementing a model 43