Unit 1 | PDF | Object Oriented Programming | Class (Computer Programming)
0% found this document useful (0 votes)
33 views

Unit 1

OOSD U1

Uploaded by

Digvijoy Ranjan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Unit 1

OOSD U1

Uploaded by

Digvijoy Ranjan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY

Ghaziabad

Subject Name: Object Oriented system Design(BCS-054)

Unit -1 IT-1(Session 2021-22) By Chitra Nasa (Asst Professor)

Introduction: The meaning of Object Orientation, object identity, Encapsulation, information hiding, polymorphism,
generosity, importance of modelling, principles of modelling, object oriented modelling, Introduction to UML, conceptual
model of the UML, Architecture.

1. What is modeling?

A model is an abstraction of something for the purpose of understanding it before building it. Because, real systems that
we want to study are generally very complex. In order to understand the real system, we have to simplify the system.

2. Why do we model?

To test a physical entity before actually building it.


• To set the stage for communication between customers and
developers.
• For visualization i.e. for finding alternative representations.
• For reduction of complexity in order to understand it.

We build models so that we can better understand the system we are developing.

3. Importance of Modeling

 Permits you to specify the structure or behavior of a system.


 Helps you visualize a system.
 Provides template that guides you in constructing a system.
 Helps to understand complex system part by part.
4. Principles of UML Modeling

1. The right models will highlight the most critical development problems. Wrong models will mislead you,
causing you to focus on irrelevant issues.
For Example: We can use different types of diagrams for different phases in software development.

2. The best models are connected to reality


3 Every model may be expressed at different levels of precision.

4. No single model is sufficient. Every non-trivial system is best approached through a small set of nearly independent
models.

6. Objects are instances of classes. They contain data and provides services. The data forms the attributes of the

object. The services are known as methods (also known as operations or functions).

7. Object Identity

Means that every object is unique and can be differentiated from other objects .Each time and object is created
the object identity is defined.
8. Encapsulation in OOP Meaning: Encapsulation refers to the bundling of data, along with the methods that
operate on that data, into a single unit.

Many programming languages use encapsulation frequently in the form of classes.

9. Object-Oriented Modeling

In software , two most common ways are to approach a model.

1. algorithms perspective.
2. object –oriented perspective.

In algorithms perspective 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,it is very hard to maintain.
10. Objects Oriented Modeling Phases

In OOM the modeling passes through the following processes:

• System Analysis
• System Design
• Object Design, and
• Final Implementation.

System Analysis

In this phase, the developer interacts with the user of the system to find out the user requirements and analyses
the system to understand the functioning of it. Based on this system study, the analyst prepares a model of the
desired system. This model is purely based on what the system is required to do.

System Design: At this stage, the complete system architecture is designed. This is the stage where the whole
system is divided into subsystems, based on both the system analysis model and the proposed architecture of
the system.

Object design decides the data structures and algorithms needed to implement each of the classes in the system withthe
help of implementation details given in the analysis model.

Final Implementation: At this stage, the final implementation of classes and relationships developed during object
design takes place a particular programming language, database, or hardware implementation (if needed).

Whole object oriented modeling is covered by using three kinds of models for a system description. These models are:

• object model,
• dynamic model, and
• functional model.(Discuss Later)
11. Advantages of Object Oriented Modeling

The systems designed using OOM are closer to the real world.
OOM designs encourage more reusability.
Reduces the development cost & time and increases quality.

12. Object Orientation

Object Orientation is a modeling and development methodology based on object oriented concept.
In which each object represent a real world entity with the ability to interact itself and with other objects

Abstraction

In system development, Abstraction helps to focus on what an object is supposed to do, before deciding how it should be
implemented.

Encapsulation

Encapsulation enables you to combine data structure and behavior in a single entity. Encapsulation helps in system
enhancement. If there is a need to change the implementation of object without affecting its external nature, encapsulation
is of great help.
Polymorphism
The decision of which procedure to use is made implicitly by each object, based on its class polymorphism makes
maintenance easier because the calling code need not be modified when a new class is added.

Inheritance
13. CHARACTERISTICS OF OBJECT ORIENTED MODELING.

• Class and Objects


• Links and Association
• Generalization and Inheritance

Class and Objects

Classes define the basic words of the system being modeled.


Classes can serve as the foundation for data modeling.
A class defines the basic attributes and the operations of the objects of that type.

The notation for a class is a box with three sections. The top section contains the name of the class in boldface type,
the middle section contains the attributes(data variable) that belong to the class, and the bottom section contains the
class’s operations (Methods).
Figure shows the class Book. Attributes of Book are title, author, publisher along with their data types.
Operations on Book are open(), close(), read().

Links and Association


Links and associations are the basic means used for establishing relationships among objects and classes of the
system.

A link is a physical or conceptual connection between objects for example, a student Name XYZ study in IGNOU.

Association
It is a relation between two classes.
If two classes in a model need to communicate with each other, there must be a link between them, and that can be
represented by an association (connector).
Note that every association has roles.

Associations may be binary, ternary, or have higher order

Multiplicity
Multiplicity in an association specifies how many objects participate in a relationship.
Multiple students can associate with a single Department and single student can associate with multiple Departments, but
there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently

Aggregation (whole/part)
It is type of Association.
It is telling about ownership.
Department Teacher
Math t1
Science t2
IT t3

Department own teacher


(whole) (part)
Person has Address is represented using two classes Person and address. Since as we can see, Address has a person is
meaningless thus person is a class and address is a class whose object is contained within the container class Person.
Here we can see ,the life time of object of address class does not depends on lifetime of person class. Thus object are
not tightly coupled.
#include <iostream>
#include<string.h>
using namespace std;
class Address
{
public:
int houseNo;
string colony,city, state;
Address(int hno, string colony, string city, string state)
{
this->houseNo = hno;
this->colony=colony;
this->city = city;
this->state = state;
}
};
class Person
{
private:
Address* address;
public:
string name;
Person(string name, Address* address)
{
this->name = name;
this->address = address;
}
void display()
{
cout<< name<< " "<< " "<< address->houseNo<<" "<<address-> colony<<" " <<address->city<< " "<<address->state<<endl;
}
};
int main(void) {
Address add1= Address(868 ,"Wave City","Ghaziabad","UP");
Person p1 = Person("Raj",&add1);
Person p2 = Person("Rahul",&add1);
p1.display();
p2.display();
return 0;
}
Composition
Strong form of aggregation.
Object life time depends
Life time of part(B) depends on life time of part (A)
Composition is actually a strong type of aggregation and is sometimes referred to as a “death” relationship.

#include <iostream>
using namespace std;
class X
{
private:
int d;
public:
void set_value(int k)
{
d=k;

void show_sum(int n)
{
cout<<"sum of "<<d<<" and "<<n<<" = "<<d+n<<endl;

}
};
class Y
{
public:
X a;
void print_result()
{
a.show_sum(5);
}

};

int main()
{
Y b;
b.a.set_value(20);
b.a.show_sum(100);
b.a.print_result();
}

14. Generalization and Inheritance

Generalization is the relationship between a class, and it defines a hierarchy of abstraction in which subclasses (one or
more) inherit from one or more superclasses.

15 Unified Modeling Language (UML) is a general purpose modelling language. The aim of UML
is to define a standard way to visualize the system has been designed.

UML is not a programming language, it is rather a visual language. The Object Management Group
(OMG) adopted Unified Modelling Language as a standard in 1997. Its been managed by OMG ever
since. International Organization for Standardization (ISO) published UML as an approved standard
in 2005. UML has been revised over the years and is reviewed periodically.
Do we really need UML?

 Complex applications need collaboration and planning from multiple teams and hence require a
clear and concise way to communicate amongst them.

 Businessmen do not understand code. So UML becomes essential to communicate with non
programmers essential requirements, functionalities and processes of the system.
 A lot of time is saved when teams are able to visualize processes, user interactions and static
structure of the system.

Diagrams in UML can be broadly classified as:


1. Structural Diagrams – Capture static aspects or structure of a system.
Component Diagrams,
Object Diagrams,
Class Diagrams
Deployment Diagrams.

1. Behavior Diagrams – Capture dynamic aspects or behavior of the system.

Use Case Diagrams,

State Diagrams,

Activity Diagrams

Interaction Diagrams.

Object Oriented Concepts Used in UML –

1. Class – A class defines the blue print i.e. structure and functions of an object.
2. Objects – Objects help us to decompose large systems and help us to modularize our system.
Modularity helps to divide our system into understandable components so that we can build our
system piece by piece. An object is the fundamental unit (building block) of a system which is
used to depict an entity.
3. Inheritance – Inheritance is a mechanism by which child classes inherit the properties of their
parent classes.
4. Abstraction – Mechanism by which implementation details are hidden from user.
5. Encapsulation – Binding data together and protecting it from the outer world is referred to as
encapsulation.
6. Polymorphism – Mechanism by which functions or entities are able to exist in different forms.

16. Conceptual Model of UML

1.Things

A diagram can be viewed as a graph containing vertices and edges. In UML, vertices are replaced by things,
and the edges are replaced by relationships. There are four types of things in UML. They are:

1) Structural things (nouns of uml – static parts)

2) Behavioral things (verbs of uml – dynamic parts)

3) Grouping things (organizational parts)

4) Annotational things (explanatory parts)


Structural things

Class: Graphically class is represented as a rectangle with three


compartments.

Interface: Graphically interface is represented as a circle or a class symbol stereotyped with interface.

Use Case: A use case is a collection of actions, defining the interactions between a role (actor) and the
system.

Example: A use case is a written description of how users will perform tasks on your website.
collaboration
A collaboration diagram, also known as a communication diagram Describe the relationships and interactions among
software objects in the Unified Modeling Language (UML).

Component: A component is a physical and replaceable part of a system. Graphically component is


represented as a tabbed rectangle. Examples of components are executable files, dll files, database tables,
files and documents.
Node: A node is a physical element that exists at run time and represents a computational resource.
Graphically node is represented as a cube. Examples of nodes are PCs, laptops, smartphones or any
embedded system.

Active Class: A class whose objects can initiate its own flow of control (threads) and work in parallel with other
objects. Graphically active class is represented as a rectangle with thick borders.

Behavioral Things
Represents the dynamic aspects of a software system.

Interaction: A behavior made up of a set of messages exchanged among a set of objects to perform a
particular task.
State Machine: The state machine diagram is also called the Statechart or State Transition diagram, which
shows the order of states underwent by an object within the system.
Grouping Things
Package: A general purpose mechanism for organizing elements into groups. Graphically package is
represented as a tabbed folder.

Annotational Things

Note: A symbol to display comments. Graphically note is represented as a rectangle with a dog ear at the top
right corner.
Relationships

Dependency: A semantic relationship, in which a change in one thing (the independent thing) may cause
changes in the other thing (the dependent thing). This relationship is also known as “using” relationship.

Generalization: Is a generalization-specialization relationship. Simply put this describes the relationship of a


parent class (generalization) to its subclasses (specializations). Also known as “is-a” relationship.

Realization: Defines a semantic relationship in which one class specifies something that another class will
perform. Example: The relationship between an interface and the class that realizes or executes that interface.
Diagram –Discuss Later

Rules : The rules enable the users to create well-formed models.

UML has rules for:


Names – What elements can be called as things, relationships and diagrams
Scope – The context that gives a specific meaning to a name
Visibility – How these names are seen and can be used by the other names

Integrity – How things properly relate to one another


Execution – What it means to run or simulate a model

Common Mechanisms

Why UML is easy to learn and use? It’s because of the four common mechanisms that apply throughout the UML. They
are:

1. Specifications
2. Adornments
3. Common divisions
4. Extensibility mechanisms

Specifications: Behind every graphical notation in UML there is a precise specification of the details that element
represents. For example, a class icon is a rectangle and it specifies the name, attributes and operations of the class.

Adornments: The mechanism in UML which allows the users to specify extra information with the basic
notation of an element is the adornments.

In the above example, the access specifiers: + (public), # (protected) and – (private) represent the visibility of
the attributes which is extra information over the basic attribute representation.

Common Divisions: In UML there is clear division between semantically related elements like: separation
between a class and an object and the separation between an interface and its implementation.
Extensibility Mechanisms
The extensibility mechanisms in UML are:

 Stereotypes – Extends the vocabulary of UML. Allows users to declare new building blocks (icons) or extend the
basic notations
 Tagged Values – Extends the properties of an UML building block. Allows us to specify extra information in the
elements specification. Represented as text written inside braces and placed under the element name. The general
syntax of a property is: { property name = value }

 Constraints – Extends the semantics of a UMLs building block such as specifying new rules or modifying existing
rules. Represented as text enclosed in braces and placed adjacent or beside the element name.

You might also like