A Review or Brief Introduction

Slides:



Advertisements
Similar presentations
Fields, Constructors, Methods
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
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.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
Object-Oriented Analysis and Design
UML Basics & Access Modifier
Writing Classes (Chapter 4)
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
CSE 501N Fall ‘09 14: Inheritance 20 October 2009 Nick Leidenfrost.
UML Review – class diagrams SE 2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
Topic 5 Introduction to UML Diagrams. 1-2 Objectives To introduce UML Diagrams A diagrammatic way of showing the relationships among classes This will.
UML Class Diagrams 1 These lecture slides are copyright (C) Marty Stepp, They may not be rehosted, sold, or modified without expressed permission.
Copyright © Curt Hill Inheritance and Polymorphism A Powerful Technique.
Object Oriented Analysis: Associations. 2 Object Oriented Modeling BUAD/American University Class Relationships u Classes have relationships between each.
Object Oriented Analysis and Design Class and Object Diagrams.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Copyright © 2015 Curt Hill Java for Minecraft Those things you should know.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Chapter 8 Specialization aka Inheritance. 2 Inheritance  Review of class relationships  Uses – One class uses the services of another class, either.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
© 2006 Pearson EducationDesign Patterns1 of 20 A Final Example: A Traffic Light Let’s model a traffic light! – here’s the spec: Have a column of two circles.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
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.
Classes, Interfaces and Packages
TK2023 Object-Oriented Software Engineering CHAPTER 11 CLASS DIAGRAMS.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
UML Review – class diagrams SE-2030 Dr. Mark L. Hornick 1.
Chapter 12 – Object-Oriented Design
Object-Orientated Analysis, Design and Programming
UML-Class Diagrams. UML-Class Diagrams Order placement problem A Company has two types of customers, corporate customers and personal customers. All.
Unified Modeling Language
Inheritance ITI1121 Nour El Kadri.
Design Class Diagrams
Object-Oriented Analysis and Design
Chapter 16 UML Class Diagrams.
Interface, Subclass, and Abstract Class Review
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Design Class Diagrams
About the Presentations
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Introduction to UML Introduction to UML Shiyuan Jin September,23,2002
Methods Additional Topics
Object Oriented Analysis and Design
A brief look at some of the new features introduced to the language
Defining Your Own Classes Part 1
Corresponds with Chapter 7
Seminar 3 UML Class Diagram.
Objects as Variables Featuring the Date Object
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Arrays in Java What, why and how Copyright Curt Hill.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Advanced Java Programming
Unified Modelling Language
Overriding Methods & Class Hierarchies
Outline Anatomy of a Class Encapsulation Anatomy of a Method
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.
Java Programming Language
Review of Previous Lesson
Object Oriented System Design Class Diagrams
Unified Modeling Language (UML)
Object-Oriented Design AND CLASS PROPERTIES
Programming in C# CHAPTER 5 & 6
Methods Coding in Java Copyright © Curt Hill.
Presentation transcript:

A Review or Brief Introduction UML Class Diagrams A Review or Brief Introduction Copyright © 2016 Curt Hill

Introduction In this presentation we wish to consider the most common UML diagrams in our trade These are class diagrams These are how we rough out the design of programs and systems in an Object Oriented fashion Copyright © 2016 Curt Hill

Class The basic class is a rectangle with one to three pieces The top portion is the class name The properties occur in one of the pieces and the methods in another Properties may be described by attributes or associations If the class is described already we may leave it at just a name Copyright © 2016 Curt Hill

Attribute Notation Each attribute is described in a way similar to what you might see in a programming language The general form is: vis name: type mult = def {propstr} Where Vis is visibility (+ or -) Name and type are obvious Mult is multiplicity Def is default Propstr shows other characteristics Name is only one that is required Copyright © 2016 Curt Hill

Multiplicity How many are there? Usually in brackets If absent there is just one This is how an array or other container class would be notated A range is shown by a two dot ellipsis [0..1] An * signifies zero or more Copyright © 2016 Curt Hill

Visibility UML is designed to work with any language Therefore it has four visibility symbols + public - private # protected ~ package These may have subtle differences from programming languages However those differences are not important here Copyright © 2016 Curt Hill

Example Here is the day from the infamous CurtDate - day: char [1] Here is another: -title: String = “None” {readonly} Next we look at a diagram Copyright © 2016 Curt Hill

An Order Object Order + received: Date [0..1] + isPrepaid: Boolean [1] + lines: OrderLine[*] {ordered} Copyright © 2016 Curt Hill

Associations An association is a graphical way to do similar things as attributes A solid line between two classes indicates an association The contained class has the name, multiplicity and other characteristics on its end Copyright © 2016 Curt Hill

Order Again Order Date Boolean OrderLine received 0..1 isPrepaid 1 lines {ordered} Boolean * OrderLine Copyright © 2016 Curt Hill

BiDirectional Association A bidirectional association is also possible Denoted by double headed arrow For two items to refer to each other usually implies pointers in C++ Such as a car object pointing at its owner with a person object pointing at an owned car Copyright © 2016 Curt Hill

Implementable Class How would we implement such a class in C++ or any other language? Most of the primitive types are obvious Variables such as lines would likely use a collection or container class Private variables may have a set/get pair of methods but a readonly variable would have get without set The next screen is an example Copyright © 2016 Curt Hill

One More Time on Order class Order { private: Date received; bool isPrepaid; list<OrderLine> lines; public: Date getReceived(){ return received;} void setReceived (Date d){ received = d; } ... }; Copyright © 2016 Curt Hill

Methods Methods are the operations of classes They implement the behaviors of the class The notation looks very similar to the attribute notation Also similar to a prototype notation of some languages We see what it takes to declare without implementation details Copyright © 2016 Curt Hill

Methods Again The general form is: vis name (parms) : rtype {propstr} Where Vis is visibility (+ or -) Name is obvious Parms are parameters and use attribute notation Rtype is return type Propstr shows other characteristics Copyright © 2016 Curt Hill

Parameters Again One feature that a parameter has that an instance variable or static variable does not is direction The three directions are: in out inout Leaving direction off assumes in Notice that C++ and Java do not distinguish between inout and out but some languages do Copyright © 2016 Curt Hill

Setters and Getters Many classes have set and get methods that give access to a single instance variable These are usually named something like setX and getX Where X is the variable name These are usually left out of the UML They do not tell us much in regards to behavior Constructors are also often left out Copyright © 2016 Curt Hill

Generalization This is a term that refers to a concept usually implemented with inheritance An ancestral class is a generalization of descendent classes If we want the ancestral class we could actually receive the descendent class Recall the person hierarchy: a person is a generalization of a student or employee Copyright © 2016 Curt Hill

Person Example Continued If a method/function requires a Person We should be able to pass an employee or student or gradstudent Similarly, anything that uses a student should be able to accept a gradstudent as well Copyright © 2016 Curt Hill

Customer Example We may have a distinction between customers that are individual people and those that are corporations We accomplish this by having a Customer class which contains the similarities and derive a CorporateCustomer and PersonalCustomer class We then state that Customer is a generalization of either of these Copyright © 2016 Curt Hill

Generalization Inheritance is usually denoted by the ancestral class (or super class or base class) shown higher Derived classes (subclasses or subtypes) are below and point to the ancestral class Copyright © 2016 Curt Hill

Person Hierarchy Person -name: string getAge(): Date Employee Student -wage: float -hours: int -hours: int -points: int getPay(): float getGPA (): float Copyright © 2016 Curt Hill

Generalization Again Although UML is supposed to be standard It is only as standardized as the user There are variations in form For example sometimes the generalization arrow is more a triangle to distinguish from other arrows Copyright © 2016 Curt Hill

Person Hierarchy Again -name: string getAge(): Date Employee Student -wage: float -hours: int -hours: int -points: int getPay(): float getGPA (): float Copyright © 2016 Curt Hill

Notes and Comments Sometimes we may want some explanation These are attached in a rectangle with folded corner attached with a dotted line to whatever it describes Copyright © 2016 Curt Hill

Commented Class Person -name: string getAge(): Date Could be part of U or not getAge(): Date Copyright © 2016 Curt Hill

Dependency A dependency exists whenever a change to one class mandates a change to another Change in class structure/interface Not a change in object value These occur for several reasons Class contains another class Class method uses another class as a parameter Class calls method of another class Copyright © 2016 Curt Hill

Dependencies Again These are things that need to be monitored Too many dependencies make a system difficult to maintain One change has a large ripple effect Dependencies are shown by a dashed arrow The dependent item points to that on which it depends Copyright © 2016 Curt Hill

An Example Order Customer CorpCust PrsnCust OrderLine * * 1 Product dateReceive: Date isPrepaid: boolean Price: Money 1 * Name [1] Address [0..1] getCreditRating(): string Dispatch close 1 If credit rating is “poor” then isPrepaid must be true lineitems * ordered PrsnCust CorpCust OrderLine creditCard creditLimit contactName Quantity: integer Price: Money monthBill(int) * * 1 salesRep 0..1 Product Employee Copyright © 2016 Curt Hill

Finally Probably need another dose of this Copyright © 2016 Curt Hill Needs a few more examples too Copyright © 2016 Curt Hill