Vous êtes sur la page 1sur 26

General OOP Concepts

CHAPTER 5

Introduction

Large programs, because of its more complexity, are more prone to errors and software errors can be expensive. The most adopted and popular programming structure programming approach, failed to show the desired results due to lack of bug-free, easy to maintain and reusable programs. The latest programming approach, Object Oriented Programming offers a new and powerful way to cope with this complexity.
2

Evolution of Software

A program serves the purpose of commanding the computer. The efficiency and usefulness of a program depends not only on proper use of commands but also on the programming language in which it is written. The two major types of programming languages are:

Low Level Languages High Level Languages

Low Level languages

LLL are machine-oriented and require extensive knowledge of computer circuits. Machine language in which instructions are written in binary code. Assembly language, in which instructions are written in symbolic names for machine operations.
4

High Level language

HLL offers English Keywords, constructs for sequence, selection, decision, use of variable and constants.

The programs written in HLL are converted into machine language using compiler or interpreter.
5

Purpose of Programming language

It should provide a vehicle for the programmer to specify actions to be executed, which requires a language that is

close to the machine.

It should provide a set of concepts for the programmer to use when thinking about what can be done, which requires a language that is close to the problem to be

solved.

Programming paradigms

Paradigms means organizing principles of a

programs. It is an approach to programming. The different programming paradigms are:

Procedural Programming:
Modular Programming: The Object Oriented Programming:
7

Procedural Programming

A program is a list of instruction where each statement tells the computer to do something. The focus is on processing, the algorithms are needed to perform the desired computation.

Languages which supports this paradigm by providing facilities for passing arguments to functions and returns value to function.
Here data is programming. given second status while
8

Modular Programming

As complexity increased, was difficult to handle list of instructions in single program. Thus a large program is broken down into smaller units i.e, functions. Thus no of functions grouped together into a larger entity called a Module.

Module : A set of related procedure with the


data they manipulate is called a Module.

Object Oriented Programming


The object oriented approach views a problem in terms of objects involved rather than procedure for doing it. Objects is an identifiable entity with some characteristics and behaviour. In OOP approach, the characteristics of an object are represented by its data and its behaviour is represented by its function associated. Therefore, in OOP object represents an entity that can store data and has an interface through functions. For e:g Orange is an object Its shape, color are characteristics. Juicy and taste are behaviour.

10

Important Terms

Object: Is an identifiable entity with some

characteristics and behaviour. Class: A class is a group of objects that share common properties and relationships. For E:g: Honda City is an Object Belongs to Class Car Car is Subclass of Automobiles Automobiles is a subclass of Vehicles
11

We can define OOP paradigm as:

Decide which classes and objects are needed

Provide a full set of operations for each class.

12

Basic Concepts of OOP

1.

2.
3. 4. 5.

The OOP has been developed with a view to overcome the drawbacks of conventional programming approaches. These general concepts of OOP are: Data Abstraction Data Encapsulation Modularity Inheritance Polymorphism
13

Data Abstraction

Abstraction is the concept of simplifying a real world concept into its essential elements. Abstraction refers to the act of representing essential features without including the background details or explanations.

For eg car driving Switch Board


14

Encapsulation

It is the way of combining both data and the functions that operate on that data under a single unit. The only way to access data is provided by the functions, which are called member function in C++. To access the data item in an object, one should call a member function in a object. For Eg: Company
15

Objects provide an approach to maintain the integrity of the program data. Since the classes use the concept of data abstraction, they are known as Abstract Data Types. Data types because these can be used to create objects of its own type. Encapsulation is a way to implement data abstraction. Encapsulation hides the details of the implementation of an object.
16

Object
Data Member Functions

Object
Data Member Functions

Object
Data Member Functions

17

Modularity

The act of partitioning a program into individual components is called modularity. Partitioning reduces its complexity to some degree and it creates a number of welldefined, documented boundaries within the program. Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules. Eg: Music System
18

Cohesion and Coupling

Cohesion: The purpose for which the function is made. It is a structure of a module.

Coupling: Connectivity all together between two modules using two or more than two variables is called coupling.

High Cohesion and Low coupling


19

Inheritance

Inheritance is the capability of one things to inherit capabilities or properties from another class.

Eg: Humans inherit certain properties like to speak, eat etc. The class Human inherits these properties from class Mammal which again inherits some of its properties from sub class Animal.
20

Why Inheritance?

Inheritance expresses the relationship, which makes it ensure the closeness with real world models. Another reason is the idea of reusability. It allows the addition to additional features to an existing class without modifying to it. It is transitive in nature. If a class A inherits properties of another class B, then all subclasses of A will automatically inherit the properties of B. Person Student Graduate Student
21

Polymorphism

Polymorphism is the ability for a message or data to be processed in more than one form. It is the concept that supports the capability of an object of a class to behave differently in response to a message or action. Eg: Humans can see in Day light like other mammals cats and dogs also. But see in Darkness only cats can see not Humans and dogs. Eg: 5+7 = 12 A + BC = ABC
22

Illustrates that a single function name can be used to handle different number and different types of arguments.

23

Advantages of OOP
1. 2.

3.

4.

5.

It models real world well. With OOP, programs are easy to understand. OOP offers classes reusability. OOP facilitates Quick Development as parallel development of classes is possible. With OOP, programs are easier to test manage and maintain.
24

Disadvantages of OOP
1.

2.

3. 4.

5.

With OPP, classes tend be overly generalized. The relations among classes become artificial at times. The OOP programs design is tricky. Also one need to do proper planning and proper design for OOP programming. Programmer need proper skills such as design skills, programming skills, thinking in terms of objects etc.
25

Activity

Create a Output Screen for booking tickets for Multiplex Theaters.


Screen 1 Screen 2 Screen 3

26