Requirements Analysis 9. 1 OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved INFO2005 Requirements Analysis Object Oriented Concepts Department of Information Systems
Requirements Analysis 9. 2 OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Learning Objectives v Why OO? v Classes & Objects v Review the UML notation v Some important concepts in OO
Requirements Analysis 9. 3 OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis 9. 4 OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis 9. 5 OO Concepts b509.ppt © Copyright De Montfort University 2000 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 may have states:
Requirements Analysis 9. 6 OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis 9. 7 OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis 9. 8 OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Classes Class describes “a group of objects with – Rumbaugh et al., 1991 Class is “a descriptor for a set of objects with similar structure & behaviour” UML V1.1
Requirements Analysis 9. 9 OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Classification v Grouping objects with the same behaviour and data. v Modifying or Extending the object v Example
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Message Passing v Objects collaborate to achieve the functional requirements v Objects communicate by passing messages –request – calls –may include parameters –some messages have
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Message Passing Borrower address name status Book status title borrow
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Encapsulation
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Encapsulation v An object has data and behaviour v Behaviour = v Data should be accessed only by object’s own operations v Operation signature specifies number and type of attributes passed to it
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Effect of Encapsulation v Object implementation hidden from other objects 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”
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 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:
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Generalisation-Specialisation
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 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
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 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:
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved Summary v 4 important characteristics of OO: –message passing –encapsulation –inheritance –polymorphism
Requirements Analysis OO Concepts b509.ppt © Copyright De Montfort University 2000 All Rights Reserved References v Bennett, S., McRobb, S. & Farmer, R. Object-Oriented Systems Analysis and Design using UML McGraw-Hill 2002 v Jacobson, I., Booch, G. and Rumbaugh, J. (1999), The Unified Software Development Process, Addison-Wesley, Reading Mass. v Rational Unified Process 2000