Learning oops concept

Hi @all

I am new to object oriented programming(oops) and i am just new to programming, i started working on python language, i am able to create an class, function etc… but i am not really aware of real world meaning of oops in software development, If anyone help me to understand the usage of oops concept it will be helpfull for improve software programming. Can anyone pls!!!

Thanks in advance…

The core objective is to encapsulate the behaviour of a thing as
distinct from how that behaviour is implemented.

A function gives a way to name some behaviour:

 def square(x):
     return x * x

so that you can write meaningful expressions. Classes do a similar thing
on a larger scale, oriented to a particular type of object. A typical
learning example might be geometric:

 class Shape:
     def area(self):
         raise NotImplementedError

 class Square(Shape):
     def __init__(self, edge_length):
         self.edge_length = edge_length
     def area(self):
         return self.edge_length ** 2

 class Circle(Shape):
     def __init__(self, radius):
         self.radius = radius
     def area(self):
         return math.pi * self.radius ** 2

 shapes = [ some list of Shape instances ]
 total_area = sum([ shape.area() for shape in shapes ])

The last line computes the area by calling a Shape’s .area() method
without any knowledge of what kind of shape it is or how the area is

This separation leads to both more readable code (because you know from
looking at it that you’re adding up areas in this case) and freedom to
implement new shapes, or existing shapes in different ways.

Sometimes object orients methods are talking about as a message passing
operation: you pass an “area” message to a shape and get back a numeric
message. This highlights the idea that the shape might be so isolated
from you that you can’t even look at its internals, perhaps even on
another machine.

In Python you can look at the internals, but the method interface is
intended to dissuade you from relying on the internals.

Cameron Simpson cs@cskk.id.au

Hi @cameron , Thanks for reply,
Please find my understanding below and comment me…
i could understand core objective is encapsulate the behaviour(means only showing wanted information to user or hiding other information), First question come into my mind why we need to hide the information, because in development perspective only developer could know what else function available in the code. why we need to do this? (i understand i am bit confused on this topic on why we need to do all this, could you give more thought on this???)

I couldn’t understand much with example could you please elabrote the example so it will be helpfull me to understand better.

Cameron, do you have any books to recommend on oop?
It so long ago leant oop that i am out of the loop on books.

There is a lot to oop that I suspect is going to be tough is handle here.

Yes, i agree you @barry-scott, before that may be any one give me why we need oops in software development life cycle (except things like reuse code, organizing code)
I am not really get what is abstraction, could you give laymen level understanding of what is abstaraction, encapsulation is?

Computer science research, and experience in industry, shows that OOP gives a huge advantage in quality, cost of implementation and cost of maintenance.

Here is one list of pros and cons Advantages and Disadvantages of OOP - GeeksforGeeks

Thanks @barry-scott , I understand from the post, oops is mainly created for developing, maintaining the software in a structured way for long use and easy use. correct me if i am not wrong.

That list is hardly a quality source of oop advantages. I think that oop honestly overcomplicates many tasks that are more easily done with a procedural or functional approach.

Are you thinking it is just for big, long lived, projects?
I use OOP for small stuff as well, becuase I find it faster for non trivia problems.

However if the problem you are solving just needs a hand full of functions then its may well not be worth the trouble of create classes, etc.

Its a matter of picking an appropiate method for the problem you are solving.

Agreed. I have seen OOP used for problem it is ill suited for.

1 Like

Cameron, do you have any books to recommend on oop?

Unfortunately no. I’m sure there are several good books about though.

OOP is an approach to programming. There are some formalisms, but also
many variations both in implementation (eg Python vs C++) and in use by

It so long ago leant oop that i am out of the loop on books.

Me too.

Cameron Simpson cs@cskk.id.au