Unit 2 : Problem Solving Through Object

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Simplifications of Context-Free Grammars
Variations of the Turing Machine
2006 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Zhongxing Telecom Pakistan (Pvt.) Ltd
Introduction to Object Oriented Design
Chapter 7 System Models.
Requirements Engineering Process
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Copyright © 2003 Pearson Education, Inc. Slide 1.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module D (Office 2007 Version) Decision Analysis.
Processes and Operating Systems
1 Hyades Command Routing Message flow and data translation.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination. Introduction to the Business.
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
Prepared by: Workforce Enterprise Services For: The Illinois Department of Commerce and Economic Opportunity Bureau of Workforce Development ENTRY OF EMPLOYER.
Local Customization Chapter 2. Local Customization 2-2 Objectives Customization Considerations Types of Data Elements Location for Locally Defined Data.
Process a Customer Chapter 2. Process a Customer 2-2 Objectives Understand what defines a Customer Learn how to check for an existing Customer Learn how.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
Chapter 6 File Systems 6.1 Files 6.2 Directories
Making the System Operational
1 Advanced Tools for Account Searches and Portfolios Dawn Gamache Cindy Bylander.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
Week 2 The Object-Oriented Approach to Requirements
Configuration management
Chapter 11: Models of Computation
Turing Machines.
Red Tag Date 13/12/11 5S.
Database Performance Tuning and Query Optimization
PP Test Review Sections 6-1 to 6-6
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
User Friendly Price Book Maintenance A Family of Enhancements For iSeries 400 DMAS from Copyright I/O International, 2006, 2007, 2008, 2010 Skip Intro.
Microsoft Confidential. We look at the world... with our own eyes...
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
By Waqas Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most.
Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation 1.
Success Planner PREPARE FOR EXAMINATIONS Student Wall Planner and Study Guide.
Benchmark Series Microsoft Excel 2013 Level 2
 Copyright I/O International, 2013 Visit us at: A Feature Within from Item Class User Friendly Maintenance  Copyright.
Jim Haywood (Product Manager for Statutory Returns) Adopted from Care - Spring Release 2014.
Chapter 6: ER – Entity Relationship Diagram
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Executional Architecture
GEtServices Services Training For Suppliers Requests/Proposals.
2004 EBSCO Publishing Presentation on EBSCOadmin.
Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do.
Chapter 10: The Traditional Approach to Design
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 10 A Monetary Intertemporal Model: Money, Prices, and Monetary Policy.
Systems Analysis and Design in a Changing World, Fifth Edition
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Chapter 12 Working with Forms Principles of Web Design, 4 th Edition.
PSSA Preparation.
Chapter 11 Describing Process Specifications and Structured Decisions
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
Chapter 13 Web Page Design Studio
By Hui Bian Office for Faculty Excellence Spring
Page 1 Orchard Harvest ™ LIS Find a Patient Training.
4/4/2015Slide 1 SOLVING THE PROBLEM A one-sample t-test of a population mean requires that the variable be quantitative. A one-sample test of a population.
Modeling Main issues: What do we want to build How do we write this down.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
© Copyright 2011 John Wiley & Sons, Inc.
Benchmark Series Microsoft Excel 2013 Level 2
Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
Introduction To System Analysis and Design
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
Presentation transcript:

Unit 2 : Problem Solving Through Object 3/27/2017 Content Software development cycle What are objects? Deriving objects from a given problem Generalization / Specialization Case Studies Appendix : a Diagram with different Names ? Dear all, I’ll be glad if you can start making up your own REVISION NOTES by consolidating as much POINTS that available, such as my notes, other tutors notes, other fellow students’ notes. As a graduated student of OUHK, I wish both teaching staff & students have OPEN minds – info sharing -- but not your TMAs :P Kenny YUEN ======== http://learn.ouhk.edu.hk/~t441063 PS: Special THANKS for Vicmon FAN [ http://learn.ouhk.edu.hk/~t430859 ], who has summarized most important points for me make up this version

A) SDLC - Software Development Life Cycle pp-3 well-defined steps to handle & manage development it avoids : problems in coordinating many developers & many programs on a large project miscommunication between developers & users SDC is cyclical, not linear also called 'waterfall model'

Simplified SDC model Requirement Phase Analysis Phase Design Phase It’s also called a WaterFall Model Analysis Phase Design Phase Implementation Phase Testing Phase Maintenance

Simple software : a single pass may suffice According to nature of common activities in s/w development, it is divided into 6 phases: Requirements phase Analysis phase Design phase Implementation phase Testing phase Maintenance phase Simple software : a single pass may suffice Sophisticated software might be too complicated to build with a single pass through these 6 phases. A single pass might only complete a portion of the features (or a software module) of the system.

An Iterative approach Maintenance Requirement Phase Analysis Phase Design Phase Implementation Phase Testing Phase Requirement Phase Analysis Phase Design Phase Implementation Phase Testing Phase … … … Requirement Phase Analysis Phase Design Phase Implementation Phase Testing Phase Maintenance

An Iterative approach the entire software development is divided into iterations. Each iteration aimed at a portion of the system and each iteration takes all except Maintenance phase iterates, cycle-by-cycle until system tested OK, moving to Maintenance Phase no. of cycles varies as system complexity & developers’ decision eg. it finished in 5 cycles with a spiral view

Pipelining Example : while some developers are working on the testing phase of an iteration, another group of developers has already started working on the requirement phase for the next iteration.  complete more projects in shorter time Project -A Requirement Phase Analysis Phase Design Phase Implementation Phase Testing Phase Project -B Requirement Phase Analysis Phase Design Phase Implementation Phase Testing Phase Time

A Completed SDC Diagram pp-9 When expected output of a phase does not meet the users’ requirements, either back to its prior phase ( 1 step back ), or back to earlier phases ( some steps back ) eg. In Implementation, when some info is missing : Programmer ask a Designer, who may go back to the Design Phase & re-design the system, or the Designer ask an Analyst, who may go back to Analysis Phase & clarify user requirements After clarifying the info, resume normal process So, a complete SDC model must allow going back to 1 or more phase(s) when necessary

Go back to appropriate phase(s) Requirement Phase meet needs Analysis Phase N Y Normal process flow meet needs Design Phase N Y meet needs Implementation Phase N Y meet needs Testing Phase Go back to appropriate phase(s) Something wrong ? N Y meet needs Maintenance N Y

OO approach to Software Development s/w developers try to model real-world scenarios & system operations by objects. relationship between classes & objects a class definition is defined for objects with same type, and entities with same attributes & behaviors When an application is executed, the relevant class definitions are used to create objects so that the objects have the appropriate attributes and behaviors. so a class is a blueprint for a group of objects of the same category, eg. made cookies (object) from CookieCutter (Class)

1) Requirements phase (SDC Activities) Objectives collect requirements (needs) from user/client who request for software (s/w) development. “needs” refer to functionalities of the software, Requirements may include software limitations sample requirements of a payroll system what types of staff are to be supported, what types of payment method are required, etc. limitations are constraints of the software, such as hardware, time limits & budget. eg. users may require a response time < 3 sec, finish the s/w on Linux platform, in 3 months without exceeding a budget of HK$ 20,000

From time to time, developers seek users’ clarification Deliverables Activity interview the client, who requested the s/w, and end user, who’ll use the s/w Common problem is miscommunication between client/user & developer because : users use business terminology (jargon), & developer have little business knowledge. From time to time, developers seek users’ clarification Deliverables developer prepare a problem statement, which summarizes all user requirements, including software limitations a problem statement help user & developer clarify the needs & limitations early in s/w development.

2) Analysis phase Objectives to understand operational details for each user requirement focus on what a system must do Activity to identify functionalities & features of the software based on the problem statement from requirements phase

Deliverable produce requirement specifications list of roles of the users of the software eg, in banking, users are customer, teller, supervisor & manager list of functionalities or operations for each role eg, in a banking, account operations are deposit, withdraw & transfer. allow Teller to perform all these operations, but only Supervisors can modify transactions made by tellers. list of operational scenarios under different conditions allow withdraw operation, if account has enough money else, reject the withdraw operation & the s/w alerts user list of business entities with their attributes & behaviors a transfer operation involves 2 accounts + a transaction record. account has an attribute, 'balance', and 2 operations, deposit & withdraw

If not enough information was collected, repeat the requirement phase Remarks these 2 phases (requirement & analysis) are programming language independent because their Objectives is to collect user requirements & to understand the operational details. If not enough information was collected, repeat the requirement phase until thoroughly clear about what the users expect and the details of all functionalities

3) Design phase Previously, developers analysis a system in business viewpoint Objectives transform requirements into technical design model real-world cases & system operations by objects Design class definitions (re-use in implementation phase) Activity From requirement specification, find attributes of objects Objects of the same type, and entities with same behaviors & attributes, are defined as a single class. consolidate Operational scenarios to well-defined steps of behavior Deliverable List of classes, each with a list of attributes and behaviors (with well-defined steps ) is produced

4) Implementation phase Objectives aims at converting the class designs derived in the design phase to actual class definitions in the chosen programming language. Activity use Java (in our course) to implement the classes, their attributes and behaviors Deliverable method bodies program codes which are ready for testing

5) Testing phase Objectives to make sure the programs do what we expected uncover software errors before releasing it to users Activity verify programs by feed in test data and then check if outputs match expected results. If un-matching, codes are examined & checked for errors After errors are found / corrected, programs are re-tested This process is repeated until all errors are corrected Deliverable a readily deployable software system

6) Maintenance phase pp-9 Objectives to fix the errors found after deployment in large & sophisticated system, not all errors can be found / corrected at testing phase in adapting to a rapidly changing world, software need to be enhanced / enriched for users to continue using Activity involves code modification, which may take much effort for improperly designed/implemented software maintenance cost will > the sum of prior 5 phases. That’s why we need a systematic way to build software Deliverable an updated software with fixed errors & enhanced feature

B) What are objects ? Real-World Objects (RWO) pp-10 Real-World Objects (RWO) Our world is made up of objects a chair, a television set, a computer everything are objects. desktop/personal computer (PC) & notebook computer are in the same category “Computer“ they are characterized by attributes such as hard disk & RAM size, CPU type/speed In OO, we call such a category a class. So, PCs are instances (or objects) of the class “Computer“

Software objects (SO) OO software use SO to model RWO, both physical things and abstract concepts or ideas. SO has attributes to mimic characteristics of RWO SO has behaviors that correspond to the actions of RWO RWO may have many characteristics & actions SO model only a subset of them for a specific problem. Thus, the same RWO may be modeled differently in different software. SO only exist while a s/w is running. The object states must be stored properly so that they can be recreated the next time when the software is run.

Object concepts attributes vs. states attributes = properties of an object states = values of properties of an object which reflect current situation of the object objects always have attributes, and their values (or states) may change over time, especially if they are manipulated in any ways the value of an attribute determines the current state of an object

message vs. behaviour in a software system, an object will never perform its behavior unless we send a message to it message type & object behavior is 1→1 mapping If an object has a behavior such as ‘doSomething ’, it is expected that it can accept a message type ‘doSomething ’ and perform the ‘doSomething ’ behaviour.

Class Diagram for a Washing Machine Attributes & behaviors of a washing machine object are identified in analysis phase. In design phase, a class definition is used to describe / model a washing machine object divided into three regions - class name attributes that each object of this class has behaviors Class Name Attributes Behaviors

Class definition Object instances wM : WashingMachine : WashingMachine object name is wM An anonymous object (object name is optional) Class Name Data Types Attributes WashingMachine wM : WashingMachine : WashingMachine brandName : String modelNumber : String capacity : double timeRequired : double consumptionRate : double height : double width : double depth : double brandName = “ABC” modelNumber = “WM-201” capacity = 5 timeRequired = 45 consumptionRate = 50 height = 880 width = 530 depth = 530 brandName = “ABC” modelNumber = “XYZ” capacity = 5 timeRequired = 45 consumptionRate = 50 height = 880 width = 530 depth = 530 start ( ) top ( ) setTimer ( hour : int ) getTimeElapsed ( ) : int start ( ) top ( ) setTimer ( hour : int ) getTimeElapsed ( ) : int start ( ) top ( ) setTimer ( hour : int ) getTimeElapsed( ) : int Class definition Object instances Behaviors ': int' indicates the returns feedback of type integer

The Given Requirements pp-15 'Start Washing' button of washing machine is pressed The incoming water valve is opened for 5 minutes.  The drum motor starts at normal speed for 15 minutes.  The outgoing water valve is opened.  The drum motor starts at high speed for 5 minutes.  The outgoing water valve is closed.  The outgoing water valve is closed.

Accomplishing tasks by objects In OO programming, tasks always involve objects. To complete a task, we expect some results will be returned from the objects or the states of some objects will be changed. Suppose the objects WashingMachine, DrumMotor, IncomingValve and OutgoingValve have been found to be appropriate. The washing operation can be accomplished by messages sent among the objects.

Modeling the washing Machine Objects pp-16 :WashingMachine 3, 8 : startNormalSpeed (15) 5, 10 : startNormalSpeed ( 5) 2, 7 : open (5) 4, 9 : open ( ) 6, 11 : close ( ) :IncomingValve :OutgoingValve :DrumMotor Modeling the washing Machine Objects

Interaction among objects pp-17~8 behaviors of an object are not performed unless it receives a message the only interaction among objects is the messages sent among them While sending a message from Sender to Receiver, the Sender assume that the Receiver can : understand this message & perform a behavior according to this message Sender concerns What the Receiver will do Sender doesn’t concern How a Receiver works Receiver can determine its own way to perform a behavior according to this message

Benefit of such interaction among objects capability of handling complexity every object (the agent) is only required to perform its own operations based on the attributes and the supplementary data in the messages (parameters) when it receives particular messages. Each object performs its own part. All objects cooperate, and they constitute a complex operation. It is much easier for analysts to : clarify a single operation of an object than analysis all scenarios when many objects are involved in a complex operation.

C) Deriving objects from a given problem core activity in analysis phase identify object/class and their attributes & behaviors from the problem statement more than 1 result may be derived, it depends on our understanding on the problem and our trade-offs eg. pp-29, methods can be defined in 2 ways. there is no fixed rule to select the best way Regardless of the derived result, make sure that the derived objects can fully model all scenarios.

Textual Analysis Given a problem statement find objects by highlighting (or underlining) the nouns and noun phrases the steps are: Determine the involved objects (and the classes) Determine the object attributes Determine the object behaviors Verify if the list of objects & behaviors is complete or not The bank system transfers an amount of money from a source account to a destination account. It first withdraws the amount from the source account and then deposits the same amount in the destination account. The bank system transfers an amount of money from a source account to a destination account. It first withdraws the amount from the source account and then deposits the same amount in the destination account.

Step 1 & 2: Identify Object/Class & Attributes nouns (& noun phases) can be : objects / Class or object attributes or. duplicated (already identified) object, or irrelevant to our model. determination criteria : Noun an Entity ? Y N Candidate Object / Class Object Attributes relevant ? Discard it if we interest in modeling the thing itself, then model it as separate class for things that we are not interested but are helpful properties of some classes, then treat them as attributes

After grouping & filtering the nouns & noun phrases, we have a list of The decision to consider whether it is necessary to model an object by class definition is based on our understanding of the problem, so there is no concrete answer.  group the nouns of the same type of entity and give it a class name After grouping & filtering the nouns & noun phrases, we have a list of class names Don’t use plural nouns. ( No “s” ) all CamelStyle (capitalize 1st letter of each word) and their attributes start with lowercase letter & use CamelStyle to concatenate the rest

Finally, determine whether an object comprises other identified objects or an object has other objects as its components CPU = CU + ALU + Reg ( ref : Von Neumann arch.) if an object has attribute for each component object, then give a name to each one.  if an object always sends messages to some objects, then the corresponding class definition has an attribute for each of them. WashingMachine has attributes (components) of IncomingValve, OutgoingValve and DrumMotor

Step 3: Identify Object Behaviors generate a list of potential object behaviors by identifying verbs & verb phases in the problem statement if 2 different verbs are referring to the same behavior, then choose any one of them.  check which object(& class) has these behaviors eg. state changes or action taken some verbs only specify that an object has attributes (rather than behavior) the output in this step is a list of object behaviors that we can add to the related classes.

Step 4 : check completeness of objects & behaviors Analysis the scenarios when messages are sending among objects. Verify/check whether : object behaviors suffice to model the scenarios, & supplementary info is needed to perform the behavior Is the list of objects & behaviors ( it ) complete ? if we can model the original scenario based on a sequence of object behaviors, then it is complete this also marks the end of the analysis phase if it cannot cooperate to finish a task, then it may be incomplete we have to re-analysis the problem & review it. 

eg. transfer $ between accounts (Analysis Phase) highlighting / underlining nouns & noun phrases Build table check entries in 1st column, for candidate Classes, if yes give a class name in 2nd column 'Class name' else write comments on 3rd column The bank system transfers an amount of money from a source account to a destination account. It first withdraws the amount from the source account and then deposits the same amount in the destination account. not an Entity but still useful copy all nouns from the requirement statement all CamelStyle Object / Class Class Name Remarks amount Supplementary info of behavior amount of money Same as amount (duplicated) bank system Bank destination account BankAccount source account both SRC & DES are accounts, so Group them as BankAccount Class

destination:BankAccount highlight Verb & Verb Phases To draw our diagram use the 2nd column of our table, draw all Classes draw arrows according to our highlighted behaviors label all arrows with the name of the behaviors label all arrows with their operational sequence filling supplementary data / parameters The bank system transfers an amount of money from a source account to a destination account. It first withdraws the amount from the source account and then deposits the same amount in the destination account. source:BankAccount 2 : withdraw (amount) :Bank 3 : deposit (amount) 1 : transfer (source, destination, amount ) destination:BankAccount

eg. transfer $ between accounts (Design Phase) a bank account should maintain its own balance So, an attribute balance is added to it. to facilitate Java implementation we have to consider some language-specific issues, like data type. Thus, double, which can keep real numbers, is chosen for the attribute balance & all the related behaviors. the resulted class definitions: Bank transfer ( source : BankAccount , destination : BankAccount , amount : double ) BankAccount balance : double withdraw ( amount : double) deposit ( amount : double)

D) Generalization & Specialization (gen-spec) Given 3 similar classes differ by name only By generalization (a new class Staff is created) gen-spec are 2 sides of the same coin Clerk Manager Director name : String staffNumber : String name : String staffNumber : String name : String staffNumber : String calculateSalary( ) salary : double calculateSalary( ) salary : double calculateSalary( ) salary : double specialized by some specific attributes / behaviors eg. commission generalizing common attributes / behaviors eg. name Staff name : String staffNumber : String calculateSalary( ) salary : double super class subclass Clerk Manager Director otPayRate : double allowance : double commission : double calculateSalary( ) salary : double calculateSalary( ) salary : double calculateSalary( ) salary : double

Inheritance & Method Overriding By Inheritance, subclass inherits all attributes/behaviors superclass Clerk, Manager, Director will inherit everything from superclass Staff : the attributes “name” & “staffNumber” & the behavior “calculateSalary” By Method Override, subclass define & use its behaviors overriding the inherited ones from super class Staff name : String staffNumber : String calculateSalary( ) salary : double Overriding Staff’s method to handle OT pays Clerk Manager Director otPayRate : double allowance : double commission : double calculateSalary( ) salary : double calculateSalary( ) salary : double calculateSalary( ) salary : double

Advantages Whatever changes to the super class’s attributes & behaviors, those changes will apply to subclasses Thus, minimizes the maintenance efforts of attributes and behaviors enables programs to be written to manipulate general Staff objects since objects of subclasses {Clerk, Manager, Director} can be treated as objects of super class {Staff}, so subclasses can accept the same messages and perform the behaviors that a super class object accepts (even though subclasses may have method overriding) Then, it is convenient to send the same message calculateSalary to every Staff object, and they will calculate their own salaries properly. This is called polymorphism

Class Hierarchy At top-level, Since Animal defines all attributes & behaviors, so Animal is a general class while the others are specific classes, middle level, Bird plays dual roles specific class of Animal general class of Hawk & Owl arrow draws from specific to general Remarks : Top level Animal weight : double age : double lifeLength : double eat( ) sleep( ) move( ) reproduce( ) Middle level general class super class, base class, parent class specific class subclass, derived class, child class Lion elephant Bird fly( ) Lizard Snake Hawk Owl

E) Case Studies With courteous of Vicmon FAN (group-8), please refer to his Web Version as follows : [ http://learn.ouhk.edu.hk/~t430859/mt201/note/unit2/noteUnit2-2.htm ]

F) Appendix - a Diagram with different Names ? Object Interaction Diagram (p-22) Operational Diagram (p-47) Message Sending Diagram (p-49) anyway it looks like “Collaboration Diagram” in UML ref. pp-89, The UML Ref Manual, Addison Wesley, 1999 UML = Unified Modeling Language ( Out syllabus )