Unit 1
Unit 1
Experience : 6 Years
Qualification : ME (CSE)
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
• Object-oriented modeling and design is a way of thinking about problems
using models organized around real-world concepts.
• The fundamental construct is the object, which combines both data structure
and behavior.
• In other words, two objects are distinct even if all their attribute values (such
as name and size) are identical.
• In the real world an object simply exists, but within a programming language
each object has a unique handle by which it can be referenced.
• Each class describes a possibly infinite set of individual objects. Each object is
said to be an instance of its class.
• An object has its own value for each attribute but shares the attribute names
and operations with other instances of the class.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
• Inheritance is the sharing of attributes and operations (features) among classes
based on a hierarchical relationship.
• The ability to factor out common features of several classes into a superclass
can greatly reduce repetition within designs and programs and is one of the
main advantages of OO technology.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
• Polymorphism means that the same operation may behave differently for
different classes. The move operation, for example, behaves differently for a
pawn than for the queen in a chess game.
• The real payoff comes from addressing front-end conceptual issues, rather
than backend implementation details.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
Modeling Concepts, Not Implementation
• Design flaws that surface during implementation are more costly to fix than
those that are found earlier.
• Its greatest benefits come from helping specifiers, developers, and customers
express abstract concepts clearly and communicate them to each other.
• The analyst must work with the requestor to understand the problem,
because problem statements are rarely complete or correct.
• The analysis model is a concise, precise abstraction of what the desired system
must do, not howit will be done.
• Application objects might control the execution of trades and present the
results.
• Application experts who are not programmers can understand and criticize a
good model.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
What Is OO Development?
■ System design- The development team devise a high-level strategy—the
system architecture—for solving the application problem.
• They also establish policies that will serve as a default for the subsequent,
more detailed portions of design.
• For example, the system designer might decide that changes to the
workstation screen must be fast and smooth, even when windows are moved
or erased, and choose an appropriate communications protocol and memory
buffering strategy.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
■ Class design.
• The class designer adds details to the analysis model in accordance with the
system design strategy.
• The class designer elaborates both domain and application objects using the
same OO concepts and notation, although they exist on different conceptual
planes.
• The focus of class design is the data structures and algorithms needed to
implement each class.
• For example, the class designer now determines data structures and
algorithms for each of the operations of the Window class.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
■ Implementation.
• Implementers translate the classes and relationships developed during class
design into a particular programming language, database, or hardware.
• Each model applies during all stages of development and acquires detail as
development progresses.
• The class model defines the context for software development—the universe
of discourse.
• The class model contains class diagrams. A class diagram is a graph whose
nodesare classes and whose arcs are relationships among classes.
2. State Model
• The state model describes the aspects of an object that change over time.
• The state model specifies and implements control with state diagrams.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
• A state diagram is a graph whose nodes are states and whose arcs are
transitions between states caused by events.
3. Interaction Model
• The interaction model describes how the objects in a system cooperate to
achieve broader results.
• The interaction model starts with use cases that are then elaborated with
sequence and activity diagrams.
• A use case focuses on the functionality of a system that is, what a system does
for users.
• A sequence diagram shows the objects that interact and the time sequence of
their interactions.
UNIT 1: Introduction to Object Oriented approach and
Object Modelling.
• An activity diagram elaborates important processing steps.
• The three models are separate parts of the description of a complete system
but are cross-linked.
1. Abstraction
• Abstraction lets you focus on essential aspects of an application while ignoring details.
• This means focusing on what an object is and does, before deciding how to implement it.
• Most modern languages provide data abstraction, but inheritance and polymorphism add
power.
• The ability to abstract is probably the most important skill required for OO development.
2. Encapsulation
• Encapsulation (also information hiding) separates the external aspects of an object, that
are accessible to other objects, from the internal implementation details, that are hidden
from other objects.
• You can change an object’s implementa-tion without affecting the applications that use it.
• You may want to change the implementation of an object to improve performance, fix a
bug, consolidate code, or support porting.
• Encapsulation is not unique to OO languages, but the ability to combine data structure
and behavior in a single entity makes encapsulation cleaner and more powerful than in
prior languages, such as Fortran, Cobol, and C.
3. Combining Data and Behavior
• The caller of an operation need not consider how many implementations exist.
Operator polymorphism shifts the burden of deciding what implementation to use
from the calling code to the class hierarchy.
• For example, non-OO code to display the contents of a window must distinguish the
type of each figure, such as polygon, circle, or text, and call the appropriate procedure
to display it.
• An OO program would simply invoke the draw operation on each figure; each object
implicitly decides which procedure to use, based on its class.
• Maintenance is easier, because the calling code need not be modified when a new
class is added.
• More important than the savings in code is the conceptual clarity from recognizing that
different operations are all really the same thing.
• This reduces the number of distinct cases that you must understand and analyze.
• OO development not only lets you share information within an application, but also
offers the prospect of reusing designs and code on future projects.
• Reuse does not just happen; developers must plan by thinking beyond the immediate
application and investing extra effort in a more general design.
5 Emphasis on the Essence of an Object
• OO technology stresses what an object is, rather than how it is used.
• The uses of an object depend on the details of the application and often change during
development.
• As requirements evolve, the features supplied by an object are much more stable than
the ways it is used, hence software systems built on object structure are more stable in
the long run.
• The benefits of an OO approach are greater than they might seem at first.
• The emphasis on the essential properties of an object forces the developer to think
more carefully and deeply about what an object is and does.
• The resulting system tends to be cleaner, more general,and more robust than it would
be if the emphasis were only on the use of data and operations.
Class Modeling
• An object is a concept, abstraction, or thing with identity that has meaning for
an application.
• All objects have identity and are distinguishable. The term identity means that
objects are distinguished by their inherent existence and not by descriptive
properties that they may have.
Object and Class Concepts
• An object is an instance—or occurrence—of a class. A class describes a
group of objects with the same properties (attributes), behavior (operations),
kinds of relationships, and semantics.
• Each process has an owner, priority, and list of required resources. Classes
often appear as common nouns and noun phrases in problem descriptions
and discussions with users.
• The notion of abstraction is at the heart of the matter. By grouping objects into
classes, we abstract a problem. Abstraction gives modeling its power and
ability to generalize from a few specific cases to a host of similar cases.
• Common definitions (such as class name and attribute names) are stored
once per class rather than once per instance. You can write operations once
for each class, so that all the objects in the class benefit from code reuse.
Class Diagrams
• Class diagrams provide a graphic notation for modeling classes and their
relationships, thereby describing possible objects.
• Class diagrams are useful both for abstract modeling and for designing actual
programs. They are concise, easy to understand, and work well in practice.
• Object diagrams are helpful for documenting test cases and discussing
examples. A class diagram corresponds to an infinite set of object diagrams.
• The UML symbol for a class also is a box. Our convention is to list the class
name in boldface, center the name in the box, and capitalize the first letter. We
use singular nouns for the names of classes.
• Class Representation:
Values and Attributes
• A value is a piece of data. You can find values by examining problem
documentation for examples.
• Different objects may have the same or different values for a given attribute.
Each attribute name is unique within a class
Values and Attributes
• The UML notation lists attributes in the second compartment of the class box.
Optional details, such as type and default value, may follow each attribute. A
colon precedes the type.
• An equal sign precedes the default value. Our convention is to show the
attribute name in regular face, left align the name in the box, and use a
lowercase letter for the first letter.
• You may also include attribute values in the second compartment of object
boxes. The notation is to list each attribute name followed by an equal sign
and the value.
• We also left align attribute values and use regular type face.
Values and Attributes
Fig: Object identifiers. Do not list object identifiers; they are implicit in models.
Operations and Methods
• An operation is a function or procedure that may be applied to or by objects in
a class.
E.X: Hire,fire, and payDividend are operations on class Company. Open, close,
hide, and redisplay are operations on class Window. All objects in a class share
the same operations.
• The same operation may apply to many different classes. Such an operation is
polymorphic; that is, the same operation takes on different forms in different
classes. A method is the implementation of an operation for a class.
Operations and Methods
• For example, the class File may have an operation print. You could implement
different methods to print ASCII files, print binary files, and print digitized
picture files. All these methods logically perform the same task—printing a
file; thus you may refer to them by the generic operation print. However, a
different piece of code may implement each method.
• An association describes a set of potential links in the same way that a class describes a
set of potential objects.
• An association describes a set of potential links in the same way that a class describes a
set of potential objects.
• The literature often describes multiplicity as being “one” or “many,” but more
generally it is a (possibly infinite) subset of the nonnegative integers.
• UML diagrams explicitly list multiplicity at the ends of association lines. The UML
specifies multiplicity with an interval, such as “1” (ex_x0002_actly one), “1..*” (one or
more), or “3..5” (three to five, inclusive).
• The special symbol “*” is a shorthand notation that denotes “many” (zero or more).
Multiplicity
• Multiplicity depends on assumptions and how you define the boundaries of a problem.
• Vague requirements often make multiplicity uncertain. Do not worry excessively about
multiplicity early in software development.
• The notion of an association end is an important concept in the UML. You can not only assign
a multiplicity to an association end, but you can give it a name as well.
• Use of association end names is optional, but it is often easier and less confusing to assign
association end names instead of, or in addition to, association names.
Association End Names
• Association end names are especially convenient for traversing associations, because you
can treat each one as a pseudo attribute.
• Each end of a binary association refers to an object or set of objects associated with a source
object.
• From the point of view of the source object, traversal of the association is an operation that
yields related objects.
• Association end names provide a means of traversing an association, without explicitly
mentioning the association.
• Association end names are necessary for associations between two objects of the same
class.
Ordering
• Often the objects on a “many” association end have no explicit order, and you
can regard them as a set.
• You can indicate an ordered set of objects by writing “{ordered}” next to the
appropriate association end.
Ordering
• Ordinarily a binary association has at most one link for a pair of objects. However, you
canpermit multiple links for a pair of objects by annotating an association end with {bag} or
{sequence}
• In Figure an itinerary is a sequence of airports and the same airport can be visited more than
once.
• Like the {ordered} indication,{bag} and {sequence} are permitted only for binary associations.
• Note: that the {ordered} and the {sequence} annotations are the same, except that the first
disallows duplicates and the other allows them. A sequence association is an ordered
bag,while an ordered association is an ordered set.
Qualified Associations
• A qualified association is an association in which an attribute called the qualifier
disambiguates the objects for a “many” association end.
• A qualifier selects among the target objects, reducing the effective multiplicity, from
“many” to “one.”
• Figure illustrates the most common use of a qualifier— for associations with one-to-many
multiplicity.
Qualified Associations
• The superclass holds common attributes, operations, and associations; the subclasses add
specific attributes, operations, and associations. Each subclass is said to inherit the
features of its superclass.
• Simple generalization organizes classes into a hierarchy; each subclass has a single
immediate superclass. There can be multiple levels of generalizations.
• Generalization is transitive across an arbitrary number of levels. The terms ancestor and
descendant refer to generalization of classes across multiple levels.
Generalization & Inheritance
• An instance of a subclass is simultaneously an instance of all its ancestor
classes.
• Each subclass not only inherits all the features of its ancestors but adds its
own specific features as well.
Abstract Class
• An abstract class is a class that has no direct instances but whose
descendant classes have direct instances.
• A concrete class is a class that is instantiable; that is, it can have direct
instances.
• In the UML notation an abstract class name is listed in an italic font. Or you
may place the keyword {abstract} below or after the name.
• An abstract operation is designated by italics or the keyword {abstract}
Multiple Inheritance
• Multiple inheritance permits a class to have more than one superclass and to
inherit features from all parents. Then you can mix information from two or
more sources.
1. Constraints on Objects:
Constraints
2. Constraints on Generalization Sets
UML defines the following keywords for generalization sets.
■ Disjoint: The subclasses are mutually exclusive. Each object belongs to
exactly one of the subclasses.
■ Overlapping: The subclasses can share some objects. An object may belong to
more than one subclass.
•Meaning:
The subclass inherits all attributes and operations of the superclass and adds new
features.
•Real-world analogy:
A Smartphone is a Phone but with added capabilities (Internet, Apps, Camera).
•Effect:
The subclass is a superset of the superclass in terms of behavior.
Example:
Superclass:Vehicle
Attributes:make,model,year
Methods:start(),stop()
Subclass:ElectricCar(extendsVehicle)
Additional Attributes:batteryCapacity
Additional Methods:chargeBattery()
UML:
Vehicle
↑
ElectricCar
Here, ElectricCar inherits everything from Vehicle and extends with batteryCapacity &
chargeBattery().
Key points for Extension:
•Increases specialization.
•Meaning:
The subclass inherits from the superclass but removes, limits, or specializes certain
behavior.
•Real-world analogy:
A TwoWheeler is a Vehicle but restricted to exactly 2 wheels (where Vehicle can have any
number of wheels).
•Effect:
The subclass represents a more constrained form of the superclass.
Superclass: Account
Attributes: accountNumber, balance
Methods: deposit(), withdraw()
Narrow existing
Purpose Add new functionality functionality