0% found this document useful (0 votes)
16 views

Chapter 1 Introduction To OOP

This document provides an introduction to programming, programming paradigms, and object-oriented programming (OOP). It defines programming as providing step-by-step instructions to a computer and discusses unstructured, procedural, and object-oriented programming paradigms. OOP is described as grouping data and functions into objects, allowing for encapsulation, inheritance, and polymorphism. The basics of OOP concepts like classes, objects, and pillars of OOP are also introduced at a high level.

Uploaded by

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

Chapter 1 Introduction To OOP

This document provides an introduction to programming, programming paradigms, and object-oriented programming (OOP). It defines programming as providing step-by-step instructions to a computer and discusses unstructured, procedural, and object-oriented programming paradigms. OOP is described as grouping data and functions into objects, allowing for encapsulation, inheritance, and polymorphism. The basics of OOP concepts like classes, objects, and pillars of OOP are also introduced at a high level.

Uploaded by

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

Chapter One

Introduction Java and Object oriented programming


What do you think about this Concept?

✓ What is programing

✓ Programming Paradigm

✓ What is OOP

✓ Basic concept of OOP

✓ Benefit of OOP
Basics of programming
✓ Computer is a device that performs tasks based on given set of step-by-step
instructions (procedures)

✓ These set of procedures (step-by-step instructions) are called algorithms also called
computer programs or soft wares.

✓ The way in which we tell/give the set of procedures or programs to a computer are
called programming languages. Examples are: C++, java, C#..

✓ The first thing with which one is confronted when writing programs is the problem

✓ We will interact with real world problem and we want to make life easier by providing a
program for the problem.

✓ In order to understand the problem, it is better to separate necessary from


unnecessary details: by this You try to obtain your own abstract view, or model, of
the problem

✓ The model focuses only on problem related stuff and that you try to define properties
of the problem

✓ These properties include


1. The data which are affected and
2. The operations which are identified by the problem

Daniel K OOP. 1
✓ In order to write a program, you need to go through several stages. These are
1. Type the text of the program into the computer

2. Translate the program text into a form the computer can use

3. Run the translated program


Programming Paradigm
 Is an approach to solve problem using some programming language.
 There are lot of programming languages that are known but all of them need to follow
some strategy.
 This methodology/ strategy is known as paradigm. There are different Programming
paradigm. Basically,
 We can classify as
o Unstructured,
o Procedural (structured) and
o Object-oriented approach.
Unstructured
 A sequence of commands which modify data which is in one global main.
 If the same statement sequence is needed at different locations, we have to write it
again.
Procedural
 Is a set of step by step instruction that the computer must follow.
 It consisting of a list of instructions organized in the form of group known as Functions.
 It has the ability to reuse the same code at different
 Places in the program without copying it.

 In general, in procedural programming we have a single program, which is divided into


small pieces called procedures.
 To enable usage of general procedures or groups of procedures also in other programs,
they must be separately available.
 Top-down design model, map out the overall program structure into separate
subsections
Daniel K OOP. 2
 The structured program mainly consists of three types of elements:
o Selection statement
o Sequence statement and
o Iteration Statements.
Drawbacks of Procedural/Structural Programming
 More Emphasis on Procedure (logic) rather than the data.
 It is hard to solve complex problems
 It shares global data so the data is vulnerable to accidental change.
 Based on security, reusability, expandability, scalability, maintainability (hard to
debug), and flexibility structured approach is failed than OOP.
Object – Oriented Programming
 Object-oriented programming groups operations and data into modular units called
objects
 Includes the best of structured programming
 Features with several new advanced concepts
 OOP allows us to decompose a problem into a number of entities called Objects and
then build data and functions (Known as Method in java) around these entities.
 Object oriented programming (OOP): is a programming paradigm/modelling approach
that represents concepts as "objects" that have.
 OOP treats data as a critical element in the program development and does not allow it
to flow freely around the system.
 It enables us to reduce the software systems complexity and/or failure.
 It ties data more closely to the functions that operate on it and protects it from
unintentional modification by other functions.
 Object-oriented programming language, objects and object interactions are the basic
elements of design.

Daniel K OOP. 3
 To create a better solution for a problem, first you have to identify the project’s
requirement (defining what is the system supposed to do) and develop a design that
satisfies them (specifying how the system should do it)
 If this process involves analyzing and designing your system from an object-oriented
point of view, it is called an object-oriented analysis-and-design (OOAD) process.
 Then we can use Object Oriented Programming to implement an object-oriented design
as a working system.
 Examples of Object-Oriented Programming languages include: C++, Java, C#...

Basic Concepts of OOP


Object
 Is a core concept, is a model or representation of real-world entity or logical idea or
concept.
 It may represent a person, a place, a bank account, a table of data or any item that the
program may handle.
 An object takes up space in the memory and has an associated address.
Class
 is a design or blue print of a real-world entity which defines the core properties and
functions
 The entire set of data and code of an object can be made a user-defined data type
using concept of a class.
 Unlike Object, class will not take any memory during creation.

 The above figure shows how a Car object can be the template for many other car
instances. Here polo, mini, and beetle are instances.

Daniel K OOP. 4
 So, in the above scenario, we will make a new class called Car that will structure a car
object characteristic (attributes) like the cars model, the color, how many passengers it
can hold, its speed etc.
 The class can define types of operations or methods that can be performed on a car
object. For e.g., the car class might specify an accelerate method, which would update
the speed attribute of the car object.
 A class is a template used to create multiple objects with similar Features. Each object
is associated with the data of type class with which they are created.
 For example, mango, apple and orange are members of class Fruit.
 The below figure shows representation of an Object.

 There are additional concepts in OOP They. Refereed as Pillars of OOP.

✓ Encapsulation

✓ Abstraction

✓ Inheritance

✓ Polymorphism
Encapsulation
 The wrapping (packaging) up of data and methods into a single unit (called class) is
known as encapsulation.
 Data encapsulation is the most remarkable feature of a class.
 The data is not accessible to the outside world and only those methods, which are
wrapped in the class, Can access it.
 This insulation (protecting) of the data from direct access by the program is called data
hiding.

Daniel K OOP. 5
Abstraction
 In inheritance, a new class is defined from a pre-existing class. Which leads to the
situation,
 The new class has all the functionality of the pre-existing class and additionally,
introduces its own specific functionality.
 The new class inherits the functionality of another existing class.
o While speaking of inheritance, the existing class is called the superclass (base
class) and the new class is called subclass (derived class).
E.g., graduate student and undergraduate student
o They have many data and method member in common
 In OOP, the concept of inheritance provides the idea of reusability.
Polymorphism
✓ Polymorphism means the ability to take more than one form.

✓ Same method/function when applied on different object gives different results.

✓ There are two types of Polymorphism.

✓ Compile Time Polymorphism like Method Overloading and

✓ Run Time Polymorphism like Method Overriding.

✓ For example, an operation may exhibit different behavior in different instances.

✓ The behavior depends on the type of data used in the operation.

Daniel K OOP. 6
Dynamic Binding
✓ It refers to the linking of a procedure call to the code to be executed in response to the
call.

✓ Dynamic binding means that the code associated with a given procedure call is not
known until the time of the call at run time

✓ It is associated with polymorphism and inheritance.

✓ A procedure call associated with a polymorphic reference depends on the dynamic type
of that reference
For example, consider the procedure ‘draw’ in the above figure. By inheritance, every
object will have this procedure. Its algorithm is, however, unique to each object and so the
draw procedure will be redefined in each class that defines the object. At run-time, the
code matching the object under current reference will be called.
Message Communication
 An object-oriented program consists of a set of objects that communicate with each
other.
 The process of programming in object-oriented language, therefore, involves the
following three basic steps:
o Creating classes that define objects and their behavior.
o Creating objects from class definitions.
o Establishing communication among objects.
 Objects communicate with one another by sending and receiving information much the
same way as people pass messages to one another.
 A message for an object is a request for execution of a procedure, and therefore will
invoke a method (procedure) in the receiving object that generates the desired result as
shown in Fig.

Daniel K OOP. 7
 A message for an object is a request for execution of a procedure, and the information

to be sent.

 For example, consider the statement Employee.Salary (name); Here, Employee is the

object, Salary is the message and name is the parameter that contains information.

Benefits of OOP
In OO approach:
 By using Inheritance, we can eliminate redundant code and extend the use of the

existing classes.

 By the principle of data hiding, we can build secure program that can’t be invaded by

the code in other parts of the program.

 It is possible to have multiple objects to coexist without any interference.

 It is easy to partition the work in a project based on object which reduce complexity.

 Object-oriented system can be easily upgraded from small to large system.

 Message communication techniques between object make the interface description

with the external system much simpler.

Daniel K OOP. 8

You might also like