Upload
emmly
View
27
Download
1
Embed Size (px)
DESCRIPTION
Illinois Institute of Technology. CS487 - Software Engineering Object -Oriented Concepts & Principle - Chapt 19 David A. Lash. Object Oriented Concepts & Principles. Object-Oriented Viewpoint - Characterize the problem domain as a set of objects with specific attributes and behaviors - PowerPoint PPT Presentation
Citation preview
CS48710-1/36
Illinois Institute of Technology
CS487 - Software Engineering
Object -Oriented Concepts & Principle - Chapt 19
David A. Lash
CS48710-2/36
Object Oriented Concepts & Principles
Object-Oriented Viewpoint - Characterize the problem domain as a set of objects with specific attributes and behaviors
– Functions and methods manipulate the objects
– Further characterize the objects into classes and subclasses
Leads to libraries of reusable classes and objects.
– Reduces time to develop & higher quality programs
– Easier to change
CS48710-3/36
Object Approach
Was software development only but now encompasses a complete SE view
– More than OOP (OO programming), should consider OORA (OO Req Analysis) OO D (design) & OO CASE.
– Engineering paradigm is more evolutionary since reuse of classes to emphasize
CS48710-4/36
Object Approach
The OO development process starts with requirements.
– Would define requirement classes
During engineering and construction & release would follow the path below:
Identifycandidate
classes
Search class
library
Build classes
unavailable
Save newclasses
On to customerevaluation
From Requirements, then planning &
Risk Analysis
CS48710-5/36
What is an object?
A tangible and/or visible thing– Customer, Part, etc.
Something that may be apprehended intellectually
– Appointment, Task, etc.
Something toward which thought or action is directed
– Order, Process, etc.
CS48710-6/36
Object Definition
An object is characterized by a number of operations and a state which remembers the effect of operations.
CS48710-7/36
What are an object’s characteristics?
Identity.– A way to distinguish between occurrences
Behavior. – How the object acts and reacts in terms of
state changes and messages (methods)
State.– The state of an object encompasses all of
the (usually static) properties of the object plus the current (usually dynamic) values of each of these properties
CS48710-8/36
Example OO Concepts - Classes, Objects & Inheritance
Assume have defined a class called Furniture and
– within that class there is an object called chair
Object: Chair--------------------Attributes:- Cost- Dimension- Location- Color
Class: Furniture--------------------Attributes:- Cost- Dimension- Location- Color
Inheritance
CS48710-9/36
Example OO Concepts - Operations & more Inheritance
Operations modify 1 or more attributes– E.g., location might be a function of building,
floor & room. Then move might modify 1 or more of building, floor & room to effect location.
Object: Chair--------------------Attributes:- Cost- Dimension- Location- ColorOperations- Buy- Sell- Weigh- Move
Class: Furniture--------------------Attributes:- Cost- Dimension- Location- Color
Operations- Buy- Sell- Weigh- Move
Inheritance
CS48710-10/36
Principles of Object Orientation
Major Elements– Classes & Objects– Abstraction– Encapsulation– Hierarchy/Inheritance– Polymorphism
CS48710-11/36
What is a class?
A class represents a template for several objects and describes how these objects are structured internally. Objects of the same class have the same definition both for their operations and for their information structures.
A.K.A an object type
CS48710-12/36
What is the instance of a class?
An instance is an object created from a class. The class describes the (behavior and information) structure of the instance, while the current state of the instance is defined by the operations performed on the instance.
CS48710-13/36
Instance of Tom from Persons
Class of persons
CS48710-14/36
Classes & Objects
An OO concept that encapsulates the data and procedures needed to describe the content and behavior of some real work entity
Attributes that describe the class are walled off by methods that manipulate the data some way
– the class encapsulates the data – the processing use methods to manipulate
data– achieves information hiding & minimizes ripple
effect.
CS48710-15/36
More On Classes & Objects
Classes also are generalized description that describe a category of objects (AKA template)
– All objects within a class inherent its attributes, and operations
A superclass is a collection of classes and subclass is a specialize instance of the class
Furniture
TableChair
Desk
Chair Instances
CS48710-16/36
Messages & Classes
OO = objects + classification + inheritance = communication
Messages are means by which objects interact– Provide stimulators to some behavior between
objects– message[dest, operation, parms]
Object: XXX--------------------Attributes:- X1- Y1Operations- Z1- A1
Object: AAA--------------------Attributes:- A2- B2Operations- X2- Y2
Msg(dest, oper, parm)
Msg(dest, oper, parm)
CS48710-17/36
Encapsulation
Grouping related information together and protecting it from the outside world. (e.g., its structure and behavior)
– E.g., grouping data (variables) and actions (methods) to form objects.
Advantages: – Internal details of data & procedures hidden
(reduces side effects of errors)– Classes contain templates of data structures &
operations factilitating reuse– Interfaces are encapsulated via messages with
details. (tends to reduce coupling).
CS48710-18/36
Hierarchy & Inheritance
Inheritance - A key difference between OO systems and conventional programming
– Subclass Y inherits all attributes & operations. – All algorithms & data structures immediately
available for reuse.– All changes and additions of the superclass are
immediately available to the subclasses. (change propagation)
Class: Kitchen_furniture--------------------Attributes:- Cost- Dimension- Location- ColorOperations- Buy- Sell- Weigh- Move
Class: Furniture--------------------Attributes:- Cost- Dimension- Location- ColorOperations- Buy- Sell- Weigh- Move
Inheritance
CS48710-19/36
More On Hierarchy & Inheritance
New attributes and operations can be added at each level of the hierarchyWhen adding a class have several options
– Class can be designed from scratch– Search class hierarchy to find one similar to
inherit from– Can restructure the class hierarchy to enable
inheritance by the new class– Can override characteristics of a superclass and
rewrite them for current class use.
CS48710-20/36
Hierarchy & Multiple InheritanceClass: X1--------------------Attributes:- Char1- Char2- Char3
+char4 +char5
Class: X2--------------------Attributes:- Char1- Char2- Char3- Char4- Char5
Class: X3--------------------Attributes:- Char1- Char2- Char3- Char4- Char5- Char6
Class: X4--------------------Attributes:- Char1- Char2- Char3- Char4- Char5
+char6 +Char7
Suppose wanted X1 to inherit Chart1, 2, 3, 4, 8
CS48710-21/36
Hierarchy & InheritanceClass: X1--------------------Attributes:- Char1- Char2- Char3
+char4 +char5
Class: X2--------------------Attributes:- Char1- Char2- Char3- Char4- Char5
Class: X3--------------------Attributes:- Char1- Char2- Char3- Char4- Char5- Char6
Class: X4--------------------Attributes:- Char1- Char2- Char3- Char4- Char5
+char6 +Char7
Suppose wanted X1 to inherit Chart1, 2, 3, 4, 8
Class: X1--------------------Attributes:- Char1- Char2- Char3
+char4
Class: X2--------------------Attributes:- Char1- Char2- Char3- Char4
Class: X2a--------------------Attributes:- Char1- Char2- Char3- Char4- Char5
+char5
Class: X2b--------------------Attributes:- Char1- Char2- Char3- Char4- Char8
CS48710-22/36
Hierarchy & InheritanceSuppose added classes benglishcar & englishmotorcycle
Class:Vehicle
Class: EnginePoweredVehicle
Class: PersonPoweredVehicle
Class: 2wheeledVehicle
Class: 4wheeledVehicle
Class: car
Class: Motorcycle
Both need operations leakOil() & eltronicFailure()
EnglishCarEnglishMotorcyle
Different parts of hierarchy? Restructure hierarchy? Copy code method in each?
enginlishthing
Multi-inheritence generally not allowed
CS48710-23/36
Single Inheritance w/ Java
Java handles single inheritance problem by:– creating a separate hierarchy with mixed
behavior classes called an interface hierarchy.– When you create a new class you can pick from
the superclass also from the other hierarchy.– The interface hierarchy is a collection of
methods (or behaviors), definitions and constants. (E.g., mathematical functions)
CS48710-24/36
Polymorphism
A facility for the same method name to be used with different objects.
Suppose had 4 graphical shapes and wanted to enable them to grow in size on the screen.
Set all shapes to be subclasses of a general class called shape.
Each object provides a grow method Therefore can call shape.grow(size); The run-time system invokes the version of grow
from the object being used at the time.
Circle circle;
Oval oval;
Rectangle rectangle;
Triangle t;
Circle.grow(change);
oval.grow(change);
rectangle(change);
t.change(change);
CS48710-25/36
More On Objects
Objects tend to be– external entities - other systems, devices,
people, – things - letters, reports, displays, – Events - sensor alert, robot movement– Roles - manager, engineer, salesperson– Organization unit - division, group, team– Places - loading dock, manufacturing floor– Structure - sensors, 4-wheeled vehicles that
define categories of objects
CS48710-26/36
More On Objects - II
From the homesafe example– extract nouns from system description and create a
list of potential objects
Potential object/class General Class homeowner role or external entitysensor external entitycontrol panel external entityinstallation occurrencesystem (AKA security sys) thingnumber, type attributes of sensormaster password thingtelephone number thingsensor event occurrenceaudible alarm external entity monitoring service external entity
CS48710-27/36
More On Objects - III
Six characteristics that should be used on each potential object:
– Retained Information - information about it must be remembered
– Needed services - have a set of identifiable operations that can change attribute’s value
– Multiple Attributes - Are the attributes “major” and useful?
– Common Attributes - can define a set that apply to all occurrences of object
– Essential requirements - External entity in problem and produces information essential to solution
CS48710-28/36
More On Objects - IV
Apply criteria to potential objects
Potential object/class General Class homeowner Fail 1,2, fail 6 OKsensor OK: All OKcontrol panel OK: all OKinstallation Rejected system (AKA security sys) OK: all OKnumber, type Fail: 3 failsmaster password Fail: 3 failstelephone number Fail: 3 failssensor event OK: All OKaudible alarm Ok 2-6 OK monitoring service Fail: 1-2 fail 6 OK
CS48710-29/36
More On Attributes
They describe the object and define & clarify it.– E.g., player - couple have
name, position, batting aver, games played name, average salary, peak salary, years left on
contract Study narrative and identify & select things
reasonably belong to object– Data items needed to define object in problem– Security system has set of attributes allow to
configure sensor_info = sensor_type + sensor_numb + alarm_threshold Alarm_response_info = delay_time + phone_numb _ alarm_type activation/deact_info = master_passwd + number_of_tries +
temp_passwd
CS48710-30/36
More On Operations
Define define the behavior of an object & change the attributes some way
– manipulate data in some way (add, delete, change)
– performance computation– monitor occurrence of an event
CS48710-31/36
More On Operations - II
Study narrative and identify reasonably belong to object
– study the “verbs” of narrative “Sensor is assigned a number & type” “Master passwd is programmed for arming &
disarming ...”– Tells us,
– assign operation for sensor object– program operation for system object– arm/disarm -> system (maybe system_status =
armed | disarmed)
CS48710-32/36
More On Operations - III
Would also consider the communication between objects:
What know activities occur during the life of the object?
– Communication between objects -> clues sensor event - message -> sensor to
display location and number cntl panel -> send -> system a reset
message to update system status audible alarm sent query message
CS48710-33/36
More On Operations
Object: System--------------------Attributes: -SystemID - phone number - system status - sensor table sensor type sensor number alarm threshold - alarm display time - telephone number - alarm threshold - master passwor - temporary password - number of tries----------------------Operations: program - display - Reset - query - modify - call
CS48710-34/36
Object-Oriented Programming
Object-oriented programming is a method of implementation in which
- programs are organized as cooperative collections of objects,
- each of which represents an instance of some class,
- and whose classes are all members of a hierarchy of classes united via inheritance relationships.
CS48710-35/36
Object-Oriented Analysis
Object-oriented analysis is a method of analysis that
– examines requirements form the perspective of the classes and objects found in the vocabulary of the problem domain.
CS48710-36/36
Object-Oriented Design
Object-oriented design is a method of design – encompassing the process of object-oriented
decomposition and – a notation for depicting both logical and
physical as well as – static and dynamic models of the system under
design.