Download presentation
Presentation is loading. Please wait.
1
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved COMP1007 Intro to Requirements Analysis Object Oriented Concepts Department of Information Systems
2
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Learning Objectives v Why OO? v Classes & Objects v Review the UML notation v Some important concepts in OO –message passing –encapsulation –inheritance –polymorphism
3
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Why OO? v Easier maintenance & extensibility of software v Supports reuse of existing software v Handles complexity well v Natural modelling (i.e. descriptions) of problem domain v Requirements traceability
4
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Objects An object is “a concept, abstraction or thing with crisp boundaries and meaning for the problem at hand.” Rumbaugh et al., 1991 An object reflects “the capabilities of a system to keep information [or] to interact” Coad and Yourdon, 1991 An object has “ state, behaviour and identity ” Booch, 1993 An object “represents a particular instance of a class. It has identity and attribute values” UML Spec V1.1
5
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Object State v Static and dynamic attributes v State is reflected by attribute values v A car object…. u make u model u mileage u dateRegistered u dateTaxed u dateTested Registered / Unregistered Taxed / Untaxed Tested / Untested may have states:
6
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Object Behaviour v We associate valid behaviour (operations) with each object v For the car object –register –tax –changeColour? v Each valid operation is invoked by a request from another object
7
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Object Identity v Object identity is intrinsic, not necessarily reflected by attribute values v Referenced by an object-id v Cars have different registrations but the registration is not the object id
8
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Classes Class describes “a group of objects with –similar properties (attributes) –common behaviour (operations) –common relationships to other objects (associations) –common semantics” Rumbaugh et al., 1991 Class is “a descriptor for a set of objects with similar structure & behaviour” UML V1.1
9
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Classification v Grouping objects with the same behaviour and data. v Modifying or Extending the object – modify existing behaviour – add further attributes or properties v Example – a savings account is a special type of account which pays interest on the balance and cannot be overdrawn
10
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Class Window {abstract, author=Ray, status=tested} +size:Area = (50,50) #visibility:Boolean=invisible +default-size:Rectange #maximum-size:Rectangle -xptr:XWindow* +display() +create() -attachXWindow(xwin:XWindow*) Window size:Area visibility:Boolean display() Implementation Detail Suppressed Analysis Level
11
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Message Passing v Objects collaborate to achieve the functional requirements v Objects communicate by passing messages –request another object to do something – calls an operation in the receiving object –may include parameters = data needed by the called operation –some messages have return values = a result of the operation
12
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Message Passing Borrower address name status Book status title borrow The borrower object sends a message to the book object The message calls the borrow operation. Result: Book.status is updated to “onLoan”. This change of attribute value also represents a state change for the book object.
13
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Encapsulation
14
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Encapsulation v An object has data and behaviour v Behaviour = operations that access the data v Data should be accessed only by object’s own operations v Operation signature specifies number and type of attributes passed to it
15
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Effect of Encapsulation v Object implementation hidden from other objects, though they may use its operations v Other objects see only operation protocols v Internal details may change significantly— no effect on rest of system v As long as operation purpose and protocol stay the same, changes don’t “ripple”
16
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved v But we want to distinguish academic and admin staff v E.g. admin staff can’t be assigned to teaching v We specialise the StaffMember base class Generalisation-Specialisation v Say we have a general Staff class:
17
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Generalisation-Specialisation
18
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Generalisation-Specialisation Instances of AdminStaff and AcademicStaff all have name, address, phone, nextOfKin attributes v (from generalised StaffMember class) AcademicStaff also has specialised associations with Module
19
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Inheritance v An example of inheritance v Gives opportunities for reuse v Minimises duplication of effort v Derived classes inherit base class reliability v Don’t violate base class encapsulation
20
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Inheritance Subclasses redefine the operation pay (signature stays the same) v Sender of message need not know class of receiving object v Inheritance allows reuse of existing class definitions v Just add extra attributes or modify behaviour as required
21
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Polymorphism Redefinition of pay operation is example of polymorphism v Same pay message can be sent to many StaffMember objects v Each uses its own pay method depending upon class: –AcademicStaff or AdminStaff
22
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved Summary v 4 important characteristics of OO: –message passing –encapsulation –inheritance –polymorphism
23
COMP1007 Intro to Requirements Analysis © Copyright De Montfort University 2002 All Rights Reserved References v Bennett, S., McRobb, S. & Farmer, R. Object-Oriented Systems Analysis and Design using UML McGraw-Hill 1999 v Jacobson, I., Booch, G. and Rumbaugh, J. (1999), The Unified Software Development Process, Addison-Wesley, Reading Mass. v Rational Unified Process 2000
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.