570 likes | 766 Views
CHAPTER 6. OBJECT ORIENTED ANALYSIS. Learning Objectives. Understand object oriented concepts Be able to understand and/or draw object oriented analysis modeling: Use case diagram Activity diagram Class diagram Sequence diagram Collaboration diagram State diagram.
E N D
CHAPTER 6 OBJECT ORIENTED ANALYSIS Object-Oriented Analysis
Learning Objectives • Understand object oriented concepts • Be able to understand and/or draw object oriented analysis modeling: • Use case diagram • Activity diagram • Class diagram • Sequence diagram • Collaboration diagram • State diagram Object-Oriented Analysis
Object-Oriented Concepts • Must be understood to apply class-based elements of the analysis model • Key concepts: • Classes and objects • Attributes and operations • Encapsulation and instantiation • Inheritance Object-Oriented Analysis
Classes • object-oriented thinking begins with the definition of a class, often defined as: • template • generalized description • “blueprint” ... describing a collection of similar items • a superclass establishes a hierarchy of classes • once a class of items is defined, a specific instance of the class can be identified Object-Oriented Analysis
Building a Class Class name Attributes Operations Object-Oriented Analysis
Encapsulation/Hiding Class encapsulates both data and the logical procedures required to manipulate the data Reduces the propagation of side effects when changes occur method # 2 method # 1 data method # 3 method # 6 method # 4 method # 5 Achieves“information hiding” Object-Oriented Analysis
Class Hierarchy PieceOfFurniture (superclass) Table Chair Desk ”Chable" Subclass inherit both attributes and operations from a superclass subclasses of the Subclasses of the furniture superclass Instances of chair instances of Chair Object-Oriented Analysis
Methods(a.k.a. Operations, Services) An executable procedure that is encapsulated in a class and is designed to operate on one or more data attributes that are defined as part of the class. A method is invoked via message passing. Object-Oriented Analysis
Attributes A collection of data values that describe a class Object-Oriented Analysis
Instances of a specific class • Inherit a class attributes and operations Class : STUDENT Object instance (object): Ali attributes : name, date of birth, etc. operations :calc_age, calc_cgpa, etc. Objects Object-Oriented Analysis
Example STUDENT Name DOB Address Phone Calculate_age Calculate_gpa Register_course Object-Oriented Analysis
Object Oriented Analysis (OOA) • Based on objects rather than data or processes • The intent of OOA is to define all classes (and the relationships and behavior with them) that are relevant to the problem to be solved • There are various OOA methods. Booch Method, Jacobson Method and Rumbaugh Method have collaborated into. Unified Approach – Unified Modeling Language (UML) Object-Oriented Analysis
THE OOA PROCESS Use Case Modeling – shows functions Class-based Modeling – Class diagram, CRC Behavioral Model – State Diagram, Sequence Diagram Object-Oriented Analysis
USE CASE MODELING • Illustrates the manner in which an actor interacts with the system • Actor= “ Anything that communicates with the system and that is external to the system” • Can be people or devices • Represent the roles that people/devices play as the system operates • Use Case • Depiction of a system’s behavior or functionality under various conditions as the system responds to requests from users • Full functioning for a specific business purpose Represent actor Represent a use case Object-Oriented Analysis
Use-Cases • A collection of user scenarios that describe the thread of usage of a system • Each scenario is described from the point-of-view of an “actor” • Each scenario answers the following questions: (eg: refer handout “Use Case Template for Surveillance”) • Who is the primary actor, the secondary actor (s)? • What are the actor’s goals? • What preconditions should exist before the story begins? • What main tasks or functions are performed by the actor? • What extensions might be considered as the story is described? • What variations in the actor’s interaction are possible? • What system information will the actor acquire, produce, or change? • Will the actor have to inform the system about changes in the external environment? • What information does the actor desire from the system? • Does the actor wish to be informed about unexpected changes? Object-Oriented Analysis
A c c e s s c a m e r a s u r v e i l l a n c e v i a t h e I n t e r n e t h o m e o w n e r Use-Case Diagram S a f e H o m e c a m e r a s C o n f i g u r e S a f e H o m e s y s t e m p a r a m e t e r s S e t a l a r m Object-Oriented Analysis
Eg: consider the interactions between a Bank Customer and an ATM Bank ATM Machine Withdraw Cash Check Balance Bank Customer Create Online Transaction Object-Oriented Analysis
Writing Use-Cases (Scenario) • Use case:Access camera surveillance-display camera views (ACS-DCV) • Actor:homeowner If I’m at remote location, I can use any PC with appropriate browser software to log on to the SafeHome Products Web site. I enter my user ID and two levels of passwords and, once I’m validated, I have access to all functionality for my installed SafeHome system. To access specific camera view, I select “surveillance” from the major function buttons displayed, I then select “pick camera”, and the floor plan of the house is displayed. I then select the camera that I’m interested in. Alternatively, I can look at thumbnail snapshots from all cameras simultaneously by selecting “all cameras” as my viewing choice. Once I choose a camera, I select “view” and a one-frame-per-second view appears in a viewing window that is identified by the camera ID. If I want to switch cameras, I select “pick a camera” and the original viewing window disappears and the floor plan of the house is displayed again. I then select the camera that I’m interested in. A new viewing window appears. • A variation of this narrative use case is an ordered sequence of user actions – refer handout “Use Case Template for Surveillance “(Pressman, R. (2005). Software Engineering : A Practitioner's Approach, 6th edition. New York : McGraw-Hill) • . Object-Oriented Analysis
Use-Case Modeling • Relationships Between Use Cases • Use cases may participate in relationships with other use-cases • Two types • Extends • Adds new behaviors or actions to a use case • Include • One use case references another use case 20.19 Object-Oriented Analysis
Example: Use-case diagram for a university registration system (Correction: arrow direction should be in opposite direction) 20.20 Object-Oriented Analysis
Activity Diagram • Supplements the use-case by providing a diagrammatic representation of procedural flow • May adds additional detail not directly mentioned by the use case Activity/Function Flow/Transition Decision Object-Oriented Analysis
An activity diagram for Access Camera surveillance Object-Oriented Analysis
ATM Authorization Baca kad Masuk kad Minta PIN Masuk PIN [Tidak] Sahkan PIN Adakah sah? [Ya] Pilih servis Object-Oriented Analysis
Class-Based Modeling • Identify analysis classes by examining the problem statement • Use a “grammatical parse” to isolate potential classes • Identify the attributes of each class • Identify operations that manipulate the attributes Object-Oriented Analysis
Analysis Classes • External entities (e.g., other systems, devices, people) that produce or consume information to be used by a computer-based system. • Things(e.g, reports, displays, letters, signals) that are part of the information domain for the problem. • Occurrences or events (e.g., a property transfer or the completion of a series of robot movements) that occur within the context of system operation. • Roles (e.g., manager, engineer, salesperson) played by people who interact with the system. • Organizational units (e.g., division, group, team) that are relevant to an application. • Places (e.g., manufacturing floor or loading dock) that establish the context of the problem and the overall function of the system. • Structures(e.g., sensors, four-wheeled vehicles, or computers) that define a class of objects or related classes of objects. Object-Oriented Analysis
Selecting Classes—Criteria • Retained Information • Needed services – have a set of identifiable operations • Multiple attributes • Common attributes • Common operations • Essential requirements Object-Oriented Analysis
CRC Modeling • Analysis classes have “responsibilities” • Responsibilities are the attributes and operations encapsulated by the class • Analysis classes collaborate with one another • Collaborators are those classes that are required to provide a class with the information needed to complete a responsibility. • In general, a collaboration implies either a request for information or a request for some action. Object-Oriented Analysis
Class: Class: Class: Description: Class: FloorPlan Description: Description: Responsibility: Collaborator: Description: Responsibility: Collaborator: Responsibility: Collaborator: Responsibility: Collaborator: defines floor plan name/type manages floor plan positioning scales floor plan for display Wall incorporates walls, doors and windows shows position of video cameras Camera CRC Modeling Object-Oriented Analysis
Class Types • Entity classes, also called model or business classes, are extracted directly from the statement of the problem (e.g., FloorPlan and Sensor). • Boundary classesare used to create the interface (e.g., interactive screen or printed reports) that the user sees and interacts with as the software is used. • Controller classesmanage a “unit of work” [UML03] from start to finish. That is, controller classes can be designed to manage • the creation or update of entity objects; • the instantiation of boundary objects as they obtain information from entity objects; • complex communication between sets of objects; • validation of data communicated between objects or between the user and the application. Object-Oriented Analysis
Responsibilities • System intelligence should be distributed across classes to best address the needs of the problem • Each responsibility should be stated as generally as possible • Information and the behavior related to it should reside within the same class • Information about one thing should be localized with a single class, not distributed across multiple classes. • Responsibilities should be shared among related classes, when appropriate. Object-Oriented Analysis
Collaborations • Classes fulfill their responsibilities in one of two ways: • A class can use its own operations to manipulate its own attributes, thereby fulfilling a particular responsibility, or • a class can collaborate with other classes. • Collaborations identify relationships between classes • Collaborations are identified by determining whether a class can fulfill each responsibility itself • three different generic relationships between classes [WIR90]: • the is-part-ofrelationship • the has-knowledge-of relationship • the depends-uponrelationship Object-Oriented Analysis
Composite Aggregate Class Object-Oriented Analysis
Associations • Two analysis classes are often related to one another in some fashion • In UML these relationships are called associations • Associations can be refined by indicatingmultiplicity(the term cardinalityis used in data modeling Object-Oriented Analysis
Multiplicity Object-Oriented Analysis
Behavioral Modeling • The behavioral model indicates how software will respond to external events or stimuli. To create the model, the analyst must perform the following steps: • Evaluate all use-cases to fully understand the sequence of interaction within the system. • Identify events that drive the interaction sequence and understand how these events relate to specific objects. • Create a sequence for each use-case. • Build a state diagram for the system. • Review the behavioral model to verify accuracy and consistency. Object-Oriented Analysis
State Representations • In the context of behavioral modeling, two different characterizations of states must be considered: • the state of each class as the system performs its function and • the state of the system as observed from the outside as the system performs its function Object-Oriented Analysis
The States of a System • state—a set of observable circum-stances that characterizes the behavior of a system at a given time • state transition—the movement from one state to another • event—an occurrence that causes the system to exhibit some predictable form of behavior • action—process that occurs as a consequence of making a transition Object-Oriented Analysis
Behavioral Modeling • make a list of the different states of a system (How does the system behave?) • indicate how the system makes a transition from one state to another (How does the system change state?) • indicate event • indicate action • draw a state diagram or a interaction diagram (sequence diagram or collaboration diagram) Object-Oriented Analysis
objects message/event lifeline (time) Sequence diagram • A representation of how events cause flow from one object to another as a function of time. • Events are identified by examining a use case • Is a shorthand version of a use case • Sequence diagram consists of: • Objects • Lifeline • Messages/Event Object-Oriented Analysis
Sequence Diagram anOrder Object Object and Class anOrder: Order Message/event prepare() needsToReorder() Self Delegation Object-Oriented Analysis
: Actor object Object A: Class A Object B: Class B messageA( ) message messageB(string) messageC( ) activation (optional) lifeline Object-Oriented Analysis
Identifying events with the Use-Case • Use case for a small portion of the SafeHome security function The homeowner uses the keypad to key in a four-digit password. The password is compared with the valid password stored in the system. If the password is incorrect, the control panel will beep once and reset itself for additional input. If the password is correct, the control panel awaits further action. Object-Oriented Analysis
Sequence Diagram Object-Oriented Analysis
Class diagram Sequence diagram Bob: ClockStaff Ali : User printRecord( ) STAFF printRecord calculateSalary CLOCKSTAFF printRecord calculateSalary COMISSIONSTAFF printRecord calculateSalary Bob: ClockStaff Ali : User calculateSalary( ) Object-Oriented Analysis
Order OrderLine orderNumberdateetc… itemnumberquantityetc… prepare() prepare() DeliveryItem itemnumberquantityetc… new() is_for ReOrderItem StockItem itemnumberquantityetc… orderNumberminQuantitydateetc… OrderEntryWindow new() choose() check():boolean remove() needsToReorder(): boolean Object-Oriented Analysis
anOrder Entry window anOrder anOrder Line aStock Item prepare() choose() * prepare() check() [check=“true”]remove() needsToReorder() [needsToReorder=“true”] AReorder Item aDelivery Item new [check=“true”]new Object-Oriented Analysis
Computer PrintServer Printer status(): integer print(file) uses print(filename) print(file) Managed by Queue store(file) Object-Oriented Analysis
print (filename) [printer busy]store(file) aComputer: Computer aPrintServer: PrintServer aPrinter: Printer aQueue: Queue aUser: User print(file) [printer free]print(file) Object-Oriented Analysis
Collaboration Diagram • Shows the relationships among objects • Consists of: • Objects • Lines connecting the objects • Messages Object A 2. Message2 3. Message3 Object C 1. message1 Object B Object-Oriented Analysis