Module I - Part A: (INFO2202 - Object Oriented Programming)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Module I – Part A

(INFO2202 – Object Oriented Programming)


Basics of Object Oriented Programming

Prepared by: Prof. Satarupa Bagchi Biswas


Computer Programming
Implement the
Need a Design an ALGORITHM ALGORITHM using
COMPUTER to that will show the path computer language
Solve it of solution →
Write a PROGRAM

COMPUTER PROGRAMMING
is a step by step procedure written
using specific computer
programming language to instruct
the computer how to work
Need to Solve a methodically towards solving a
PROBLEM problem. EXECUTE the
Repetitively Program
Computer Programming

Computer Program

Procedure Oriented Object Oriented


Programming Programming
Procedure Oriented vs. Object Oriented
Programming

Procedural Programming: Object Oriented Programming:

• A programming model which is derived from • A programming model which is based upon
structured programming, based upon the the concept of objects.
concept of calling procedure. • Objects contain data in the form of attributes
• Procedures/ routines/ subroutines/ functions and code in the form of methods.
simply consist of a series of computational • Computer programs are designed using the
steps to be carried out. concept of objects that interact with real
• During a program’s execution, any given world.
procedure might be called at any point, • Most popular OOP languages are class-based,
including by other procedures or itself. where classes determine the types of objects.
Top Down vs. Bottom Up Approach
Top Down vs. Bottom Up Approach
HITK Database
Level 2 ………..
Management System

AEIE Dept. Database IT Dept. Database CSE Dept. Database


Management System Management System Management System ……… Level 1

CSE Dept. (Sec A) CSE Dept. (Sec B)


Database Database
Level 0 ……….. Management System Management System
Top Down vs. Bottom Up Approach
Advantages of Object Oriented Programming over
Procedural Programming
Data Hiding → Security
Mapping with the Real World
Code Reusability
Data Abstraction
Data Encapsulation Object Oriented Programming
Inheritance may lead to -
Polymorphism
▪ Overloading
▪ Dynamic Binding
✓ no solution,
Exception Handling ✓ missing module,
Message Passing ✓ difficulty to track and solve
an error
Object-Oriented System Design
▪ Object Oriented Model is the way of constructing new objects from pre-existing objects.

▪ There are two categories of elements in an object-oriented system –


1. Major Elements − By major, it is meant that if a model does not have any one of these
elements, it ceases to be object oriented. The four major elements are −
✓ Abstraction
✓ Encapsulation
✓ Modularity
✓ Hierarchy

2. Minor Elements − By minor, it is meant that these elements are useful, but not
indispensable part of the object model. The three minor elements are −
✓ Typing
✓ Concurrency
✓ Persistence
Major Elements
Abstraction
An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of
objects. Thus it provides crisply defined conceptual boundaries, relative to the perspective of the viewer.

Encapsulation
Encapsulation is the process of compartmentalizing the elements of an abstraction that constitutes its
structure and behavior.

Modularity
Modularity is the property of a system that has been decomposed into a set of cohesive and loosely
coupled modules.

Hierarchy
Hierarchy is a ranking of ordering of abstractions. The two most important hierarchies in a complex
system are its class structure (‘is a’ or Generalization/specialization or Inheritance) and object structure
(‘part of’ or whole part).
Minor Elements
Typing
A class is visualized as a type having properties distinct from any other types. Typing is the enforcement of the notion
that an object is an instance of a single class or type. It also enforces that objects of different types may not be generally
interchanged; and can be interchanged only in a very restricted manner if absolutely required to do so.
The two types of typing are −
• Strong Typing − Here, the operation on an object is checked at the time of compilation.
• Weak Typing − Here, messages may be sent to any class. The operation is checked only at the time of execution.

Concurrency
• In an object-oriented environment, there are active and inactive objects.
• The active objects have independent threads of control that can execute concurrently with threads of other objects.
• The active objects synchronize with one another as well as with purely sequential objects.

Persistence
• An object occupies a memory space and exists for a particular period of time.
• In traditional programming, the lifespan of an object was typically the lifespan of the execution of the program that
created it. This property by which an object continues to exist even after its creator ceases to exist is known as
persistence.
Object & Class: Their Relationship
❑ A Class is a user defined blueprint or prototype
from which objects are created. It represents the
set of properties or methods that are common to Identity
all objects of one type.

State
❑ An Object is instance of class and represents
real life entities. An object consists of :
▪ State: It is represented by attributes or
properties of an object. Behavior
▪ Behavior: It is represented by methods which
reflects response of an object with other
objects.
▪ Identity: It gives a unique name to an object
that can be used for inter-object interaction.
Object & Class: Their Relationship
Generalization and Specialization:

License-number
Fuel-type
Make
Color

Sun-roof Route-id Tonnage


Association, Aggregation and Composition
Association refers to the The Composition is the
relationship between strong type of association.
multiple objects. It refers to An association is said to
how objects are related to composition if an Object
each other and how they are owns another object and
using each other's another object cannot exist
functionality. without the owner object.

Aggregation is a weak
association. An association
is said to be aggregation if
both Objects can exist
independently.
Association, Aggregation and Composition
Association

Is a Has a

Inheritance
Aggregation Composition

Part of
Association, Aggregation and Composition
Composition
Aggregation
Head

Hand Student Class

Leg
Meta Class
Objects
In object-oriented programming, a metaclass is a class whose
instances are classes.
instance of
Just as an ordinary class defines the behavior of certain objects,
a metaclass defines the behavior of certain classes and their
instances.
Classes
Not all object-oriented programming languages support
metaclasses. Among those that do, the extent to which
instance of
metaclasses can override any given aspect of class behavior
varies.

For instance, in Python, the built-in class type is a metaclass: Metaclasses


instances of class type are themselves a class of objects.

You might also like