Topics. Instance object. Instance object. Fundamentals of OT. Object notation. How do objects collaborate? Pearson Education 2007 Appendix (RASD 3/e)

Similar documents
Appendix Fundamentals of Object Technology

Τεχνολογία Λογισμικού

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

What Is Object-Orientation?

Classes and Objects. Again: Distance between points within the first quadrant. José Valente de Oliveira 4-1

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Goals of the Lecture UML Implementation Diagrams

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Goals of the Lecture Object Constraint Language

Java Inheritance. Class ADT (Abstract Data Type) Interface. Classes implement the concept of ADT: Interfaces define interaction contracts: Rui Moreira

Goals of this Lecture Activity Diagram Example

CS 11 C track: lecture 1

From last week. Lecture 5. Outline. Principles of programming languages

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

n We have discussed classes in previous lectures n Here, we discuss design of classes n Library design considerations

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Architectural styles for software systems The client-server style

n Haskell n Covered syntax, lazy evaluation, static typing n Algebraic data types and pattern matching n Type classes n Monads and more n Types

Computers and Scientific Thinking

Python Programming: An Introduction to Computer Science

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Data Structures and Algorithms. Analysis of Algorithms

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

Chapter 4 Remote Procedure Calls and Distributed Transactions

Exercise Set: Implementing an Object-Oriented Design

Behavioral Modeling in Verilog

A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON

The Magma Database file formats

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

Abstract Data Types (ADTs) Stacks. The Stack ADT ( 4.2) Stack Interface in Java

BEA Tuxedo. Creating CORBA Server Applications

Requirements Analysis

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

WYSE Academic Challenge Sectional Computer Science 2005 SOLUTION SET

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

What are Information Systems?

implement language system

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Task scenarios Outline. Scenarios in Knowledge Extraction. Proposed Framework for Scenario to Design Diagram Transformation

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Analysis of Algorithms

Linked Lists 11/16/18. Preliminaries. Java References. Objects and references. Self references. Linking self-referential nodes

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Τεχνολογία Λογισμικού

Extending The Sleuth Kit and its Underlying Model for Pooled Storage File System Forensic Analysis

Appendix D. Controller Implementation

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Modern Systems Analysis and Design Seventh Edition

Outline. Research Definition. Motivation. Foundation of Reverse Engineering. Dynamic Analysis and Design Pattern Detection in Java Programs

CIS 121. Introduction to Trees

Schema for the DCE Security Registry Server

Java net programming II

n Haskell n Syntax n Lazy evaluation n Static typing and type inference n Algebraic data types n Pattern matching n Type classes

Abstract Syntax Trees. AST Data Structure. Visitor Interface. Accept methods. Visitor Methodology for AST Traversal CS412/CS413

Overview. Chapter 18 Vectors and Arrays. Reminder. vector. Bjarne Stroustrup

Pearson Education 2005 Chapter 5 (Maciaszek - RASD 2/e) 2

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

Definitions. Error. A wrong decision made during software development

Analysis of Algorithms

CSE 417: Algorithms and Computational Complexity

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

How do we evaluate algorithms?

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Lazy Type Changes in Object-oriented Database. Shan Ming Woo and Barbara Liskov MIT Lab. for Computer Science December 1999

BEA WebLogic Server. Programming WebLogic Enterprise JavaBeans

Last Class. Announcements. Lecture Outline. Types. Structural Equivalence. Type Equivalence. Read: Scott, Chapters 7 and 8. T2 y; x = y; n Types

. Written in factored form it is easy to see that the roots are 2, 2, i,

Software development of components for complex signal analysis on the example of adaptive recursive estimation methods.

Chapter 4 Threads. Operating Systems: Internals and Design Principles. Ninth Edition By William Stallings

Exceptions. Your computer takes exception. The Exception Class. Causes of Exceptions

Elementary Educational Computer

Data diverse software fault tolerance techniques

top() Applications of Stacks

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Keywords Software Architecture, Object-oriented metrics, Reliability, Reusability, Coupling evaluator, Cohesion, efficiency

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

Python Programming: An Introduction to Computer Science

Oracle Server. What s New in this Release? Release Notes

Chapter 3 Classification of FFT Processor Algorithms

n The C++ template facility provides the ability to define n A generic facility allows code to be written once then

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

BOOLEAN MATHEMATICS: GENERAL THEORY

CHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

Threads and Concurrency in Java: Part 1

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

Threads and Concurrency in Java: Part 1

Service Oriented Enterprise Architecture and Service Oriented Enterprise

Heaps. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Priority Queues. Binary Heaps

Baan Tools User Management

CS211 Fall 2003 Prelim 2 Solutions and Grading Guide

Introduction to OSPF. ISP Training Workshops

Transcription:

Appedix (RASD 3/e) MACIASZEK, L.A. (2007): Requiremets Aalysis ad System Desig, 3 rd ed. Addiso Wesley, Harlow Eglad ISBN 978-0-321-44036-5 Appedix Fudametals of Object Techology Pearso Educatio Limited 2007 Topics Istace object Class Variables, methods, ad costructors Associatio Aggregatio ad compositio Geeralizatio ad iheritace Abstract class Appedix (Maciaszek - RASD 3/e) 2 Fudametals of OT BOOCH, G. (1994): Object Orieted Aalysis ad Desig with Applicatios, 2 d ed, The Bejami/Cummigs Publ Object has State Behavior Idetity (equal idetical) Objects ad atural systems Istace object Class a abstractio (geeric descriptio) for a set of objects a class for objects (but better to avoid the term object class because a class ca be istatiated ito a object object class object would soud a bit strage) Istace object a istace of a class object, istace, but ot object istace Class object a istatiated class (everythig i a object orieted system is a BOOCH, G. (1994): Object Orieted Aalysis ad Desig with Applicatios, 2 d ed, object) The Bejami/Cummigs Publ Appedix (Maciaszek - RASD 3/e) 3 Appedix (Maciaszek - RASD 3/e) 4 Object otatio objectame: classame attributeame: [type] = value How do objects collaborate? : Orde r a role that may objects ca play c1 : Course course_umber = COMP227 course_ame = Requiremets Aalysis ad Systems Desig c1 : Course :Course c1 aoymous object classame suppressed No compartmet for operatios i objects! Exceptio prototypical (delegatio-based) laguages, such as Self or Newto 1. ship(ord : ) 2. getproducts(ord : ) : Shipmet : Stock a message ivokig a operatio o a object (umbers do ot imply ay sequece of executio) 4. reorder(prd : Product) 3. aalyzelevels( ) : Purchase Appedix (Maciaszek - RASD 3/e) 5 Appedix (Maciaszek - RASD 3/e) 6 MACIASZEK (2007): Req Aalysis & Syst Desig 1

Appedix (RASD 3/e) How objects idetify each other? object idetifier - OID Object logevity Persistet object outlives the executio of the program swizzlig to covert persistet OID (disk address) to trasiet OID (memory address) Trasiet object c1 : Course CCC888 course_umber = COMP227 course_ame = Requiremets Aalysis ad Systems Desig teacher: idetity = TTT999 OIDs to implemet associatios c1 : Course course_umber = COMP227 course_ame = Requiremets Aalysis ad Systems Desig c2 : Course teacher teacher course course t1 : Teacher Appedix (Maciaszek - RASD 3/e) 7 Appedix (Maciaszek - RASD 3/e) 8 Trasiet lik How does a object kow the OID of aother object if there is o persistet lik? Previous access to a object still memorized i some program variable Search o the database A map object that associates objects to other objects by logical idetifiers (primary keys) or similar meas Creatig a ew object Message passig crs_ref.getcoursename(out crs_ame) i, out, ad i/out argumets Most OO laguages do ot make such distictio explicit I Java: message argumets of primitive data types are passed by value act as iput argumets the chage of argumet values ot possible because the operatio acts o a copy of the argumet pass by value for o-primitive data types results i the operatio receivig the referece of the argumet, ot its value the referece ca be used to access ad possibly modify the attribute values withi the passed object the above elimiates the eed for explicit i/out argumets retur type of a operatio substitutes a eed for explicit out argumets operatio ca retur oly oe retur value or o value at all (void) however, it ca retur o-primitive type (i.e. a object of ay complexity) Appedix (Maciaszek - RASD 3/e) 9 Appedix (Maciaszek - RASD 3/e) 10 Class, attributes Role ames / attributes desigatig a class Class a overloaded term! Class ame ordernumber : Iteger orderdate : Date ordervalue : Currecy the theshipmet Shipmet ship(ord : ) Attributes aalysis model Operatios() Course course_umber : Strig course_ame : Strig order_umber : Iteger order_date : Date order_value : Currecy ordernumber : Iteger orderdate : Date ordervalue : Currecy theshipmet : Shipmet Shipmet the : ship(ord : ) implemetatio model Appedix (Maciaszek - RASD 3/e) 11 Appedix (Maciaszek - RASD 3/e) 12 MACIASZEK (2007): Req Aalysis & Syst Desig 2

Appedix (RASD 3/e) Attribute visibility private attributes ad public operatios operatios ecapsulate attributes Purchase - purchasenumber : Strig - purchasedate : Date - purchasevalue : Currecy + reorder(prd : Product) Operatios i object collaboratio : 1. ship(ord : ) 2. getproducts(ord : ) 3. aalyzelevels( ) : Shipmet : Stock 4. reorder(prd : Product) : Purchase Purchase purchasenumber : Strig purchasedate : Date purchasevalue : Currecy Product Stock getproducts(ord : ) : Collectio aalyzelevels() reorder(prd : Product) Shipmet Purchase BOOCH, G. (1994): Object Orieted Aalysis ad Desig with Applicatios, 2 d ed, The Bejami/Cummigs Publ ship(ord : ) reorder(prd : Product) Appedix (Maciaszek - RASD 3/e) 13 Appedix (Maciaszek - RASD 3/e) 14 Operatio, visibility, scope, class object method procedure that implemets a operatio message ame = method ame sigature = list of formal argumets of a method visibility scope istace scope whe operatio ivoked o istace object (fidempage()) class scope whe operatio ivoked o class object (fidaverageage()) Class object most prog. lag. do ot istatiate class object they oly provide a sytax to refer to the class ame i order to access a class-scope attribute or call a classscope operatio static attribute/operatio Example ext slide Class-scope scope attributes ad operatios - example Studet studetid : S trig studetname : S trig umberofs tudets : it maxcoursesp ersemester : it <<static>> averagestudetage() : double public class Studet private Strig studetid; //accessible via Studet s operatios private Strig studetname; //accessible via Studet s operatios private static it umberofstudets; //accessible oly to Studet s static methods, such as averagestudetage() public static it maxcoursespersemester; //accessible via Studet:: maxcoursespersemester public static double averagestudetage() implemetatio code here //callable by referrig to the class ame Studet::averageStudetAge() //callable also with a object of the class std.averagestudetage() Appedix (Maciaszek - RASD 3/e) 15 Appedix (Maciaszek - RASD 3/e) 16 Variables, methods, costructors Associatio Variable ame for a storage space data member variable declared i a class istace variable (istace scope) class variable (class scope) local variable variable declared i a method body Method implemetatio of a operatio method prototype = ame + sigature + retur type overloaded methods same ames, differet sigatures Costructor special method to istatiate objects of the class costructor ame = class ame costructor has o retur type class must have at least oe costructor ivoked with the ew keyword Studet std22 = ew Studet(); //default costructor ordernumber : Iteger orderdate : Date ordervalue : Currecy the theshipmet OrdShip Shipmet shipmetid : Strig shipmetdate : Date carrier : Strig ship(ord : ) Appedix (Maciaszek - RASD 3/e) 17 Appedix (Maciaszek - RASD 3/e) 18 MACIASZEK (2007): Req Aalysis & Syst Desig 3

Appedix (RASD 3/e) Associatio degree Biary Uary (sigular) Terary Associatio multiplicity 0..1 0.. 1..1 1.. maagedby 0..1 Employee maagerof 0.. Teacher taughtby 1.. 1..1 ismaagedby isichargeof 0.. teaches 0.. CourseOfferig Appedix (Maciaszek - RASD 3/e) 19 Appedix (Maciaszek - RASD 3/e) 20 Associatio lik ad extet Associatio class Lik associatio istace represets a roleame ca be a collectio of refereces Extet set of associatio istaces i the figure, the exted of the associatio is five (five liks) CourseOfferig Studet 1 Lik 1 with 3 refereces Lik 2 Lik 3 Shipmet 1 Shipmet 2 Assessmet mark : List(Number) totalmark : Number grade : Byte Parameterized type 2 Lik 5 Lik 4 with 2 refereces Shipmet 23 Appedix (Maciaszek - RASD 3/e) 21 Appedix (Maciaszek - RASD 3/e) 22 Compositio ad aggregatio Compositio aggregatio by value Aggregatio aggregatio by referece Properties: Trasitivity Asymmetry Existece depedecy Implemeted by buried refereces or ier classes ext slides Book Chapter Sectio is_part_of has Crate BeerBottle Implemetig aggregatio by buried referece ot differet to associatio by meas of variable with private visibility however, i Java, classes caot have private visibility subset classes must have public or package visibility title : Strig Book search(what : Strig) : boolea Book() -thebook -thechapter Chapter text : Text figure : Graphics search(what : Strig) : boolea Chapter() -thebook public class Book private Strig title; private Chapter thechapter[]; private TableOfCotets thetableofcotets; public Book() //default costructor public boolea search(strig what) retur true; -thetableofcotets 1 TableOfCotets g eerate() : V oid TableOfCotets() Appedix (Maciaszek - RASD 3/e) 23 Appedix (Maciaszek - RASD 3/e) 24 MACIASZEK (2007): Req Aalysis & Syst Desig 4

Appedix (RASD 3/e) Implemetig aggregatio by ier classes title : S trig <<ier>> TableOfCotets geerate() : Void TableOfCotets() -toc 1 Book displaytoc() : Void search(what : S trig) : bo olea Book() -ch <<ier>> Chapter text : Text figure[ ] : Graphics search(what : Strig) : boolea Chapter(chNum : it) outer class istatiates ier objects i its ow costructor ier class ca be private (accessible oly from outer class) public class Book private Strig title; private Chapter[] ch; private TableOfCotets toc; public Book(...)... toc = ew TableOfCotets(); ch = ew Chapter[umberChapters]; for (it i=0; i<umberchapters; i++) ch[i] = ew Chapter(); public Void displaytoc() toc.geerate(); retur; private class TableOfCotets private Void geerate()... Geeralizatio A subclass iherits the structure ad behavior of its superclass BOOCH, G. (1994): Object Orieted Aalysis ad Desig with Applicatios, 2 d ed, The Bejami/Cummigs Publ Not a good visualizatio of geeralizatio. Subclasses iherit types, ot values (a ose ot a log ose)! Appedix (Maciaszek - RASD 3/e) 25 Appedix (Maciaszek - RASD 3/e) 26 Geeralizatio Polymorphism Perso fullname : Strig dateofbirth : java.util.date age() : it getyear() : it getyear(date : java.util.date) : it Perso() Employee datehired : java.util.da te salary : it leaveetitlemet : it leavetake : it remaiigleave() : it Employee() public class Perso private Strig fullname; private Date dateofbirth; public Perso()... public it age() retur getyear() - getyear(dateofbirth); public class Employee exteds Perso private Date datehired; private it salary; private it leaveetitlemet; private it leavetake; public Employee()... public it remaiigleave() retur leaveetitlemet - leavetake; Perso fullname : Strig dateofbirth : java.util.date age() : it P erso() Employee datehired : java.util.date salary : it leaveetitlemet : it leavetake : it remaiigleave() : it Employee() public class Maager exteds Employee private Date dateappoited; private it leavesupplemet; public Maager()... public it remaiigleave() it mrl; mrl = super.remaiigleave() + leavesupplemet; retur mrl; Maager dateappoited : java.util.date leavesupplemet : it remaiigleave() : it Maager() The same sigature (operatio ame ad the umber ad type of argumets) Appedix (Maciaszek - RASD 3/e) 27 Appedix (Maciaszek - RASD 3/e) 28 Multiple iheritace Perso fullname : Strig dateofbirth : Date age() : Iteger Multiple classificatio Multiple iheritace A class may have may superclasses, but a sigle class must be defied for each object Multiple classificatio A object is simultaeously the istace of two or more classes Teacher Tutor S tudet PostgraduateStudet The problem arises if Perso is specialized i few orthogoal hierarchies Perso ca be Employee or Studet, Male or Female, Child or Adult,, etc. Without multiple classificatio eed to defie classes for each legal combiatio betwee the orthogoal hierarchies ChildFemaleStudet etc. Appedix (Maciaszek - RASD 3/e) 29 Appedix (Maciaszek - RASD 3/e) 30 MACIASZEK (2007): Req Aalysis & Syst Desig 5

Appedix (RASD 3/e) Dyamic classificatio A object does ot oly belog to multiple classes but it ca gai or lose classes over its lifetime A Perso object ca be just a employee oe day ad a maager (ad employee) aother day I most curret object-orieted programmig eviromets, a object caot chage its class after it has bee istatiated (created) Appedix (Maciaszek - RASD 3/e) 31 Abstract class Paret class that will ot have direct istace objects Abstract class caot istatiate objects because it has at least oe abstract operatio public abstract class public abstract Double retalcharge(); V ideotape V ideotape() VideoDisk public class VideoDisk exteds public... public Double retalcharge() retur ull; Appedix (Maciaszek - RASD 3/e) 32 Iterface vs abstract class Iterface a defiitio of a sematic type with attributes (costats oly) ad operatios but without actual declaratios (implemetatios) of operatios classes that implemet the iterface provide the declaratios Abstract class has udesirable effect of the fragile base class problem Ulike abstract classes iterfaces are helpful for modelig situatios that ask for multiple iheritace iterface does ot implemet (eve partially) ay of its methods but still, pure abstract class iterface i case of iterface, ay class i the system ca implemet it, ot just the subclasses a class ca implemet ay umber of iterfaces iterface defies a referece type that separates cliet objects from the implemetatio chages i the supplier objects the implemetatio of the iterface ca chage ad the cliet object may ot be affected Multiple implemetatio iheritace ot allowed i Java VideoTape VideoTape() Not allowed i Java! VideoDisk VideoEquipmet purchaseprice : Double dateofpurchase : java.sql.date VideoPlayer VideoCamera Appedix (Maciaszek - RASD 3/e) 33 Appedix (Maciaszek - RASD 3/e) 34 Implemetig Java iterface public iterface Double retalcharge(); VideoPlayer VideoPlayer() SoudSystem VideoEquipmet purchaseprice : Double dateofpurchase : java.sql.date VideoCamera Usig iterface to elimiate depedecy to supplier ChargeCalculator getretalcharge() : Double ChargeCalculator() <<uses>> thevideo public class ChargeCalculator thevideo; public Double getretalcharge() retur thevideo.retalcharge(); VideoEquipmet purchaseprice : Double dateofpurchase : java.sql.date VideoTape VideoTape() VideoDisk public class VideoPlayer exteds VideoEquipmet implemets public VideoPlayer()... public Double retalcharge() retur ull; VideoTape V ideodisk VideoTape() VideoPlayer V ideop layer() SoudSystem VideoCamera Appedix (Maciaszek - RASD 3/e) 35 Appedix (Maciaszek - RASD 3/e) 36 MACIASZEK (2007): Req Aalysis & Syst Desig 6

Appedix (RASD 3/e) Summary Each object has a state, behavior ad idetity There are istace objects ad class objects Class defies attributes ad operatios There are three kids of relatioships associatio, aggregatio, geeralizatio Geeralizatio provides the basis for polymorphism ad iheritace Commercial programmig eviromets support multiple iheritace directly (C++, C#) or by meas of iterfaces (Java) Multiple ad dyamic classificatio is still ot supported commercially Abstract classes ad iterfaces are importat i modelig Appedix (Maciaszek - RASD 3/e) 37 MACIASZEK (2007): Req Aalysis & Syst Desig 7