OOP Unit 1
OOP Unit 1
1. Class
It is a user-defined data type, which holds its data members and member functions, which can be
accessed and used by creating an instance of that class. A class is like a blueprint for an object.
For Example:
Consider the Class of Cars. There may be many cars with different names and brands but all of
them will share some common properties like all of them will have 4 wheels, Speed Limit,
Mileage range, etc. So here, the Car is the class, and wheels, speed limits, and mileage are their
properties.
An Object is an instance of a class that holds data (values) in its variables. Data can be accessed by
its functions. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object
is created) memory is allocated.
Real Life Examples of Class and Objects with its attributes and
behaviour
Object Class
Object allocates memory when it is created. Class doesn't allocated memory when it is
created.
Example: Jaguar, BMW, Tesla, etc. Example: Car.
Page 3
Principles (or features) of object oriented programming:
Abstraction
Encapsulation
Inheritance
Polymorphism
Abstraction
Data abstraction is one of the most essential and important features of object-oriented programming.
Abstraction means displaying only essential information and hiding the details. Data abstraction
refers to providing only essential information about the data to the outside world, hiding the
background details or implementation.
Advantage
Data Hiding
It reduce the complexity
Properties of Encapsulation
1. Data Protection: It provides data integrity and maintains the consistency of the
object'sstate.
2. Information hiding: Encapsulation hides the internal details of an object, protecting
the datafrom unauthorized access or modification.
Inheritance:
Inheritance is the process by which one object can acquire the properties of another.
The capability of a class to derive properties and characteristics from another class is called
Inheritance. Inheritance is one of the most important features of Object Oriented Programming.
Sub Class: The class that inherits properties from another class is called Sub class or Derived
Class.
Super Class: The class whose properties are inherited by a sub-class is called Base Class or
Super class.
Example:
In a real-life example of polymorphism, a person at the same time can have different characteristics. A
man at the same time is a father, a husband, and an employee. So the same person possesses different
behavior in different situations. This is called polymorphism.
An object retains its identity even if some or all of the values of variables or definitions of
methods change over time.
Object identity is a stronger notion of identity than typically found in programming languages or
in data models not based on object orientation.
Several forms of identity:
value: A data value is used for identity (e.g., the primary key of a tuple in a relational
database).
name: A user-supplied name is used for identity (e.g., file name in a file system).
built-in: A notion of identity is built-into the data model or programming languages, and
no user-supplied identifier is required (e.g., in OO systems)
Generosity:
Generosity is a technique for defining software components that have m 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.
It is a process that allows a function or a class to work with different-different data types.
That type of function is called Template Function.
Model-
A model is a simplification of reality. A model provides the blueprints of a system. Models may
encompass detailed plans, as well as more general plans. A model may be structural, emphasizing
the organization of the system, or it may be behavioral, emphasizing the dynamics of the system.
We build model so that we can better understand system we are developing.
The Unified Modeling Language (UML) is a general-purpose modeling language. The main
aim of UML is to define standard way visualize the design of a system. You can think of UML
as a way to create blueprints so that software is fully understood by the designer before any
coding begins. UML is not a programming language, it is a visual language.
Or
The UML is a graphical language for visualizing, specifying, constructing, and documenting the
artifacts of a software-intensive system. The UML gives you a standard way to write a system's
blueprints.
Importance of Modeling
Aims of modeling
We build models so that we can better understand the system we are developing.
Through modeling, we achieve four aims.
1. Model help us to visualize a system
Page 11
Principle of Modeling:
Four basic 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.
In other words, choose your models well. The right models will brilliantly illuminate the most
wicked development problems, offering insight that you simply could not gain otherwise; the
wrong models will mislead you, causing you to focus on irrelevant issues.
4. No single model is sufficient. Every nontrivial system is best approached through a small
set of nearly independent models.
To understand the architecture of such a system, you need several complementary and interlocking
views: a use case view, a design view, implementation view, and a deployment view. Each of these
views may have structural, as well as behavioral, aspects. Together, these views represent the blueprints
of software.
In software, there are several ways to approach a model. The two most common ways are
1. Algorithmic perspective
2. Object-oriented perspective.
1. Algorithmically
The traditional view of software development takes an algorithmic perspective.
In this approach, the main building block of all software is the procedure or function.
This view leads developers to focus on issues of control and the decomposition of larger
algorithms into smaller ones.
As requirements change and the system grows, systems built with an algorithmic focus turn out
to be very hard to maintain.
2. Object-Oriented
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.
A class is a description of a set of common objects. Every object has identity, state, and
behavior.
An Overview of 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.
Specifying
Constructing
Documenting
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
Requirements
Architecture
Design
Source code
Project plans
Tests
Prototypes
Releases
2. Rules
3. Common Mechanisms
1. Things
2. Relationships
3. Diagrams
2. Behavioral things
3. Grouping things
4. Annotational things
These things are the basic object-oriented building blocks of the UML. You use them to write well-
formed models.
1. Structural Things:
They are nouns of UML model. These are the static parts that represent elements that are either
conceptual or physical. It includes class, interface, collaboration, use case, active class, component, and
node.
2. Behavioral Things:
Behavioral things are the dynamic parts of UML models. These are the verbs of a model.
There are two primary kinds of behavioral things
1. Interaction
2. state machine.
3. Grouping Things:
These are the organizing parts of UML models. These are the boxes into which a model can be
decomposed
It includes packages.
4. Annotational Things:
These are the explanatory parts of UML models.
It includes notes.
1. Dependency
2. Association
3. Generalization
4. Realization
These relationships are the basic relational building blocks of the UML. We use them to write well- formed
models.
1. Dependency:
A 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.
2. Association:
An association is a structural relationship that describes a set of links, a link being a connection
among objects.
Graphically an association is rendered as a solid line, possibly directed, occasionally including a
label, and often containing other adornments, such as multiplicity and role names.
3. Generalization:
A generalization is a specialization/generalization relationship in which objects of the specialized
element (the child) are substitutable for objects of the generalized element (the parent).
1. Class diagram
2. Object diagram
3. Use case diagram
4. Sequence diagram
5. Collaboration diagram
6. State diagram
7. Activity diagram
8. Component diagram
9. Deployment diagram
Class diagrams that include active classes address the static process view of a system.
Object diagram
Object diagrams represent static snapshots of instances of the things found in class diagrams
These diagrams address the static design view or static process view of a system
Use case diagrams address the static use case view of a system.
These diagrams are especially important in organizing and modeling the behaviors of a system
Interaction Diagrams
Both sequence diagrams and collaboration diagrams are kinds of interaction diagrams
Sequence diagrams and collaboration diagrams are isomorphic, meaning that you can take one
and transform it into the other
They are especially important in modeling the behavior of an interface, class, or collaboration
and emphasize the event-ordered behavior of an object.
An activity diagram is a special kind of a state chart diagram that shows the flow from activity to
activity within 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.
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
1. Specifications
2. Adornments
3. Common divisions
4. Extensibility mechanisms
1. Specifications
They provide 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
2. 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.
3. Common Divisions
In modeling object-oriented systems, the world often gets divided in at least a couple of ways.
4. Extensibility Mechanisms
The UML's extensibility mechanisms include
1. Stereotypes
2. Tagged values
3. Constraints
As Figure illustrates, the architecture of a software-intensive system can best be described by five interlocking
views. Each view is a projection into the organization and structure of the system, focused on a particular
aspect of that system.
With the UML, the static aspects of this view are captured in use case diagrams
Design View
The design view of a system encompasses the classes, interfaces, and collaborations that form the
vocabulary of the problem and its solution.
This view primarily supports the functional requirements of the system, meaning the services that
the system should provide to its end users.
Process View
The process view of a system encompasses the threads and processes that form the system's
concurrency and synchronization mechanisms.
This view primarily addresses the performance, scalability, and throughput of the system.
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.
Each of these five views can stand alone so that different stakeholders can focus on the issues of
the system's architecture that most concern them.
The UML permits you to express every one of these five views and their interactions.