Unit - 1 (Part 1)
Unit - 1 (Part 1)
Object oriented methods enable us to create sets of objects that work together synergistically to
produce software that better module their problem domains than similar systems produced by
traditional techniques. The system created using object oriented methods are easier to adapt
changing requirements, easier to maintain, more robust, promote greater design. The reasons
why object orientation works:
1
• Makes implementation easier.
• Provide overall better communication.
Promotion of Reusability:
Objects are reusable because they are modeled directly out of real world.
The classes are designed generically with reuse. The object orientation adds inheritance, which is
a powerful technique that allows classes to built from each other. The only differents and
enhancements between the classes need to be designed and coded. All the previous functionality
remains and can be reused without change.
2
world. world.
Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc.
Object:
Objects are composite data types. An object provides for the storage of multiple data values in a
single unit. Each value is assigned a name which may then be used to reference it. Each element
in an object is referred to as a property. Object properties can be seen as an unordered list of
name value pairs contained within the container object.
Object comes in two flavors. There are system defined objects, which are predefined and come
with the JavaScript parser or with the browser running the parser. And there are user defined
objects, which the programmer creates.
Objects are key to understanding object-oriented technology.
Look around right now and you'll find many examples of real-world objects: your dog, your
desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state
(name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have
state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing
pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a
great way to begin thinking in terms of object-oriented programming.
Software objects are conceptually similar to real-world objects: they too consist of state and
related behavior. An object stores its state in fields (variables in some programming languages)
and exposes its behavior through methods (functions in some programming languages). Methods
operate on an object's internal state and serve as the primary mechanism for object-to-object
communication. Hiding internal state and requiring all interaction to be performed through an
object's methods is known as data encapsulation— a fundamental principle of object-oriented
programming. Consider a bicycle, for example:
3
Object is an instance of a class. Class is an entity in which data and functions are
organized. Each object has a class which defines its data and behavior. When program is
executed, the objects interact by sending messages to one another. Object has some
characteristics explained below.
Abstraction:
Abstraction refers to the act of representing essential features without including the
background details or explanations.
4
Real life example of Abstraction is ATM Machine; All are performing operations on the ATM
machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can't know
internal details about ATM.
Encapsulation:
Wrapping up of data and functions into a single unit (class) is known as encapsulation. The
data is not accessible to the outside world and only those functions which are wrapped in
the class can access it.
Inheritance:
Inheritance is the process by which objects of one class acquire the properties of object of
another class. It supports the concept of hierarchical classification. In OOP, the concept of
inheritance provides the idea of reusability.
Polymorphism:
Polymorphism means ability to take more than one form. An operation may exhibit different
behaviors in different instances. The behavior depends upon the types of data used in
operation. Ex. Addition of two numbers, concatenation in case of string.
5
The process of making an operator to exhibit different behavior in difference instances is
known as operator overloading. Polymorphism is extensively used in implementing
inheritance.
Generosity:
Generosity is a technique for defining software components that have more than one
interpretation depending on the data types of parameters. It allows the declaration of data
items without specifying their exact data type. Such unknown data types (generic data type)
are resolved at the time of their usage based on the data type of parameters during a function
call.
6
Some other benefits of OOPs:
• Through inheritance, we can eliminate redundant code and extend the use of existing
classes.
• We can build programs from standard working modules that communicate with one
another.
• The principle of data hiding helps the programmer to build secure programs.
• It is possible to have multiple instances of an object to co-exist without any interference.
• The data – centered design approach enables us to capture more details of a model in
implementable form.
• Object oriented systems can be easily upgraded from small to large systems.
• Software complexity can be easily managed.
Importance of modeling:
We build models so that we can better understand the system we are developing There are
several advantages of modeling:
7
Principles of Modeling:
1. The choice of what models to create has a profound influence on how a problem is
attacked and how a solution is shaped.
If you build a system through the eyes of a database developer, you will likely focus on
entity-relationship models that push behavior into triggers and stored procedures. If you
build a system through the eyes of a structured analyst, you will likely end up with models
that are algorithmic-centric, with data flowing from process to process. If you build a
system through the eyes of an object-oriented developer, you'll end up with a system whose
architecture is centered around a sea of classes and the patterns of interaction that direct how
those classes work together.
2. Every model may be expressed at different levels of precision.
A quick and simple executable model of the user interface is exactly what you need; at other
times, you have to get down and dirty with the bits, such as when you are specifying cross-
system interfaces or wrestling with networking bottlenecks. In any case, the best kinds of
models are those that let you choose your degree of detail, depending on who is doing the
viewing and why they need to view it. An analyst or an end user will want to focus on
issues of what; a developer will want to focus on issues of how. Both of these stakeholders
will want to visualize a system at different levels of detail at different times.
3. The best models are connected to reality.
Achilles heel of structured analysis techniques is the fact that there is a basic disconnect
between its analysis model and the system's design model. Failing to bridge this chasm
causes the system as conceived and the system as built to diverge over time. In object-
oriented systems, it is possible to connect all the nearly independent views of a system into one
semantic whole.
4. No single model is sufficient. Every nontrivial system is best approached through a
small set of nearly independent models.
The operative phrase here is "nearly independent." In this context, it means having models
that can be built and studied separately but that are still interrelated. As in the case of a
building, you can study electrical plans in isolation, but you can also see their mapping to
the floor plan and perhaps even their interaction with the routing of pipes in the plumbing
plan.
8
Object Oriented Modeling:
In software, there are several ways to approach a model. The two most common ways are
1. Algorithmic perspective
2. Object-oriented perspective
1. Algorithmic perspective:
2. Object-oriented perspective :
The contemporary view of software development takes an object-oriented perspective. In
this approach, the main building block of all software systems is the object or class. Simply
put, an object is a thing, generally drawn from the vocabulary of the problem space or the
solution space; a class is a description of a set of common objects. Every object has identity
(you can name it or otherwise distinguish it from other objects), state (there's generally some
data associated with it), and behavior (you can do things to the object, and it can do things to
other objects, as well).
Introduction to UML:
• The Unified Modeling Language is a standard language for writing software blueprints.
The UML may be used to visualize, specify, construct, and document the artifacts of a
software-intensive system.
• The UML is appropriate for modeling systems ranging from enterprise information
systems to distributed Web-based applications and even to hard real time embedded
systems. It is a very expressive language, addressing all the views needed to develop and
then deploy such systems.
The UML is a language for
➢ Visualizing
➢ Specifying
➢ Constructing
➢ Documenting
9
Visualizing: The UML is more than just a bunch of graphical symbols. Rather, behind each
symbol in the UML notation is a well-defined semantics. In this manner, one developer can write
a model in the UML, and another developer, or even another tool, can interpret that model
unambiguously
Specifying: means building models that are precise, unambiguous, and complete.
Constructing: the UML is not a visual programming language, but its models can be directly
connected to a variety of programming languages
Documenting: a healthy software organization produces all sorts of artifacts in addition to raw
executable code. These artifacts include
1.Requirements
2.Architecture
3.Design
4.Source code
5.Project plans
6.Tests
7.Prototypes
8.Releases
10
Conceptual Model of UML :
To understand the UML, you need to form a conceptual model of the language, and this requires
learning three major elements: the UML's basic building blocks, the rules that dictate how those
building blocks may be put together, and some common mechanisms that apply throughout the
UML.
Things are the abstractions that are first-class citizens in a model; relationships tie these things
together; diagrams group interesting collections of things.
11
These things are the basic object-oriented building blocks of the UML. You use them to write
well-formed models.
Structural things are the nouns of UML models. These are the mostly static parts of a model,
representing elements that are either conceptual or physical. In all, there are seven kinds of
structural things.
1. Classes
2. Interfaces
3. Collaborations
4. Use cases
5. Active classes
6. Components
7. Nodes
Class is a description of a set of objects that share the same attributes, operations, relationships,
and semantics. A class implements one or more interfaces. Graphically, a class is rendered as a
rectangle, usually including its name, attributes, and operations.
Interface
Interface is a collection of operations that specify a service of a class or component. An interface
therefore describes the externally visible behavior of that element. An interface might represent
the complete behavior of a class or component or only a part of that behavior. An interface is
rendered as a circle together with its name. An interface rarely stands alone. Rather, it is
typically attached to the class or component that realizes the interface.
Collaboration defines an interaction and is a society of roles and other elements that work
together to provide some cooperative behavior that's bigger than the sum of all the elements.
Therefore, collaborations have structural, as well as behavioral, dimensions. A given class might
participate in several collaborations.
Graphically, a collaboration is rendered as an ellipse with dashed lines, usually including only its
name
12
Use case
• Use case is a description of set of sequence of actions that a system performs that yields
an observable result of value to a particular actor
• Use case is used to structure the behavioral things in a model.
• A use case is realized by a collaboration. Graphically, a use case is rendered as an ellipse
with solid lines, usually including only its name
Active class is just like a class except that its objects represent elements whose behavior is
concurrent with other elements. Graphically, an active class is rendered just like a class, but with
heavy lines, usually including its name, attributes, and operations
Component is a physical and replaceable part of a system that conforms to and provides the
realization of a set of interfaces. Graphically, a component is rendered as a rectangle with tabs
Node is a physical element that exists at run time and represents a computational resource,
generally having at least some memory and, often, processing capability. Graphically, a node is
rendered as a cube, usually including only its name
13
Behavioral Things are the dynamic parts of UML models. These are the verbs of a model,
representing behavior over time and space. In all, there are two primary kinds of behavioral
things
1. Interaction
2. state machine
Interaction
Interaction is a behavior that comprises a set of messages exchanged among a set of objects
within a particular context to accomplish a specific purpose. An interaction involves a number of
other elements, including messages, action sequences and links. Graphically a message is
rendered as a directed line, almost always including the name of its operation
State Machine
State machine is a behavior that specifies the sequences of states an object or an interaction goes
through during its lifetime in response to events, together with its responses to those events. State
machine involves a number of other elements, including states, transitions, events and activities.
Graphically, a state is rendered as a rounded rectangle, usually including its name and its
substates
Grouping Things:-
1. are the organizational parts of UML models. These are the boxes into which a model can be
decomposed
2. There is one primary kind of grouping thing, namely, packages.
Package:-
14
• A package is a general-purpose mechanism for organizing elements into groups.
Structural things, behavioral things, and even other grouping things may be placed in a
package
• Graphically, a package is rendered as a tabbed folder, usually including only its name
and, sometimes, its contents
Annotational things are the explanatory parts of UML models. These are the comments you
may apply to describe about any element in a model.
A note is simply a symbol for rendering constraints and comments attached to an element or a
collection of elements. Graphically, a note is rendered as a rectangle with a dog-eared corner,
together with a textual or graphical comment
Relationships in the UML: There are four kinds of relationships in the UML:
1. Dependency
2. Association
3. Generalization
4. Realization
Dependency:-
Dependency is a semantic relationship between two things in which a change to one thing may
affect the semantics of the other thing. Graphically a dependency is rendered as a dashed line,
possibly directed, and occasionally including a label
Association
an association is a structural relationship among classes that describes a set of links, a link being
a connection among objects that are instances of the classes. Aggregation is a special kind of
association, representing a structural relationship between a whole and its parts. Graphically, an
association is rendered as a solid line, possibly directed, occasionally including a label, and often
containing other adornments, such as multiplicity and end names
Aggregation
15
a generalization is a specialization/generalization relationship in which the specialized element
(the child) builds on the specification of the generalized element (the parent). The child shares
the structure and the behavior of the parent. Graphically, a generalization relationship is rendered
as a solid line with a hollow arrowhead pointing to the parent,
16
important in modeling the behavior of an interface, class, or collaboration and emphasize the
event-ordered behavior of an object.
Activity diagram
An activity diagram is a special kind of a statechart diagram that shows the flow from activity to
activity within a system. Activity diagrams address the dynamic view of a system. They are
especially important in modeling the function of a system and emphasize the flow of control
among objects
Component diagram
A component diagram shows the organizations and dependencies among a set of components.
Component diagrams address the static implementation view of a system.They are related to
class diagrams in that a component typically maps to one or more classes, interfaces, or
collaborations
Deployment diagram
A deployment diagram shows the configuration of run-time processing nodes and the
components that live on them. Deployment diagrams address the static deployment view of an
architecture
Rules of the UML
The UML's building blocks can't simply be thrown together in a random fashion. Like any
language, the UML has a number of rules that specify what a well-formed model should look
like. A well-formed model is one that is semantically self-consistent and in harmony with all its
related models.
The UML has semantic rules for
1. Names What you can call things, relationships, and diagrams
2. Scope The context that gives specific meaning to a name
3. Visibility How those names can be seen and used by others
4. Integrity How things properly and consistently relate to one another
5. Execution What it means to run or simulate a dynamic model
Models built during the development of a software-intensive system tend to evolve and may be
viewed by many stakeholders in different ways and at different times. For this reason, it is
common for the development team to not only build models that are well-formed, but also to
build models that are
1. Elided Certain elements are hidden to simplify the view
2. Incomplete Certain elements may be missing
3. Inconsistent The integrity of the model is not guaranteed
Common Mechanisms in the UML
UML is made simpler by the presence of four common mechanisms that apply consistently
throughout the language.
1. Specifications
2. Adornments
3. Common divisions
4. Extensibility mechanisms
Specification that provides a textual statement of the syntax and semantics of that building
block. The UML's specifications provide a semantic backplane that contains all the parts of all
the models of a system, each part related to one another in a consistent fashion
17
Adornments Most elements in the UML have a unique and direct graphical notation that
provides a visual representation of the most important aspects of the element. A class's
specification may include other details, such as whether it is abstract or the visibility of its
attributes and operations. Many of these details can be rendered as graphical or textual
adornments to the class's basic rectangular notation.
Common Divisions In modeling object-oriented systems, the world often gets divided in several
ways.
First, there is the division of class and object. A class is an abstraction; an object is one concrete
manifestation of that abstraction. In the UML, you can model classes as well as objects, as
shown in Figure. Graphically, the UML distinguishes an object by using the same symbol as its
class and then simply underlying the object's name.
In this figure, there is one class, named Customer, together with three objects: Jan (which is
marked explicitly as being a Customer object), :Customer (an anonymous Customer object), and
Elyse (which in its specification is marked as being a kind of Customer object, although it's not
shown explicitly here).
Almost every building block in the UML has this same kind of class/object dichotomy. For
example, you can have use cases and use case executions, components and component instances,
nodes and node instances, and so on.
Second, there is the separation of interface and implementation. An interface declares a contract,
and an implementation represents one concrete realization of that contract, responsible for
faithfully carrying out the interface's complete semantics. In the UML, you can model both
interfaces and their implementations, as shown in Figure.
Interfaces and Implementations
18
In this figure, there is one component named SpellingWizard.dll that provides (implements) two
interfaces, IUnknown and ISpelling. It also requires an interface, IDictionary, that must be
provided by another component.
Almost every building block in the UML has this same kind of interface/implementation
dichotomy. For example, you can have use cases and the collaborations that realize them, as well
as operations and the methods that implement them.
Third, there is the separation of type and role. The type declares the class of an entity, such as an
object, an attribute, or a parameter. A role describes the meaning of an entity within its context,
such as a class, component, or collaboration. Any entity that forms part of the structure of
another entity, such as an attribute, has both characteristics: It derives some of its meaning from
its inherent type and some of its meaning from its role within its context (Figure).
Extensibility Mechanisms The UML provides a standard language for writing software
blueprints, but it is not possible for one closed language to ever be sufficient to express all
possible nuances of all models across all domains across all time. For this reason, the UML is
opened-ended, making it possible for you to extend the language in controlled ways. The UML's
extensibility mechanisms include
• Stereotypes
Stereotype extends the vocabulary of the UML, allowing you to create new kinds of
building blocks that are derived from existing ones but that are specific to your problem
• Tagged values
A tagged value extends the properties of a UML building block, allowing you to create
new information in that element's specification
• Constraints
A constraint extends the semantics of a UML building block, allowing you to add new
rules or modify existing ones
Architecture
A system's architecture is perhaps the most important artifact that can be used to manage these
different viewpoints and so control the iterative and incremental development of a system
throughout its life cycle.
Architecture is the set of significant decisions about
1. The organization of a software system
19
2. The selection of the structural elements and their interfaces by which the system is composed
3. Their behavior, as specified in the collaborations among those elements
4. The composition of these structural and behavioral elements into progressively larger
subsystems
The architectural style that guides this organization: the static and dynamic elements and their
interfaces, their collaborations, and their composition.
Software architecture is not only concerned with structure and behavior, but also with usage,
functionality, performance, resilience, reuse, comprehensibility, economic and technology
constraints and trade-offs, and aesthetic concerns.
UML plays an important role in defining different perspectives of a system. These perspectives
are:
Design View
Implementation View
Process View
Deployment View
Use case View
And the centre is the Use Case view which connects all these four. A Use case represents the
functionality of the system. So the other perspectives are connected with use case.
20
Implementation View
The implementation view of a system encompasses the components and files that are used to
assemble and release the physical system.
This view primarily addresses the configuration management of the system's releases, made up
of somewhat independent components and files that can be assembled in various ways to
produce a running system.
Deployment View
The deployment view of a system encompasses the nodes that form the system's hardware
topology on which the system executes.
This view primarily addresses the distribution, delivery, and installation of the parts that make up
the physical system.
21