Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,764 members, 7,809,941 topics. Date: Friday, 26 April 2024 at 05:34 PM

Understanding Object Oriented Programming (OOP) - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Understanding Object Oriented Programming (OOP) (1445 Views)

A Beginners Guide To Object-oriented Programming (OOP) In PHP 5+ / Fundamentals Of All Object Oriented Programming(oop) Languages / Criticism Of Object Oriented Programming (2) (3) (4)

(1) (Reply) (Go Down)

Understanding Object Oriented Programming (OOP) by chatykrew(m): 2:32pm On Mar 19, 2007
cheesy
hi i have a problem, i have tried to understand OOP object oriented programming but i tend not to grasp the term and i really want to get in to progmg in OOP. PLs can anyone take a topic to simplify it to my understanding - dummy like me in OOP. shocked

THANKS
Re: Understanding Object Oriented Programming (OOP) by Seun(m): 10:30am On Mar 20, 2007
Start here: en.wikipedia.org/wiki/OOP and ask questions about what you don't understand wink.
Re: Understanding Object Oriented Programming (OOP) by dag(m): 6:28pm On Mar 20, 2007
for you to understand OOP, first you have to have a primer knowledge of proframming and software development in procedural form and why the concept of OOP was initiated. As softwares became more complex issues like maintaining the software and upgrading the software (maintainability and scalability) became of major concern to developers. OOP provides a slotuion to that and many other problems it solves. OOP also allows for reusabilty based on the concept of encapsulation and abstraction, OOP also brings the advantage of extensibilty based on the function of inheritance and seamless robust functionality based on polymorphism. There is a thread were @Parosky gave a very detailed explanation on OOP it would be very helpfull to you guess you take the pains and look for it it is here somewhere.

Let me give you a programming scenario were OOP is of great use.
say you work for an engineering software company, your company produce software that perform many engineering calculations, now if 90% of the softwares you design would need to do some form of algebraic factorisation and say your company produces many variety of these software, wouldnt it be painstaking to continue to write the same factorization code for say 50 different products. With OOP you can just author an object of class factorize, compile it as a dll or better yet an assembly and all you do is create a reference to the class from were ever you want to implement it and call the factorise function.

Abstract Class

Public Class Factorisation

Public variable1 As Integer

'Declare other variables

Public Function factorise(ByVal Variable As Integer, , ) As Integer

'Implement Factorisation algorithm here

End Functio

End Class

The class above authored in visual basic .net is quite a very simple class (do not copy my style for declaring properties), now imagine that the factorise function was more complex say 200 lines, wont a class really help here. now to implement this you just go in a breeze.

Implementing Abstract Class in vb.net

Sub Implement()

Dim MyFactor As New Factorisation
Dim Value as Integer

Value = MyFactor.Factorise(variable1, , )

End Sub

Now thats all you need to call this function any time you want to use it any were. got to go see my mum would have said more sorry
Re: Understanding Object Oriented Programming (OOP) by chatykrew(m): 4:37pm On Jul 16, 2007
OK but if i may say i undertsand oop, can this analogy be correct?

man (object) >> sperm(method) >> woman(object) >> pregnancy (event) >> baby (object)+encapsulation, inheritance.

Wat i mean is the man is an object gives his sperm (method) to the woman(object). the woman becomes pregnant(event) and later reacts and produces a baby(object) which conatains(inheritance) the chromosomes of the two objects.

please i hope someone undertsands and corrects/improves this analogy. thanks
Re: Understanding Object Oriented Programming (OOP) by ade2kay(m): 11:56am On Jul 17, 2007
What i mean is the man is an object gives his sperm (method) to the woman(object).

Actually, man(object) "gives sperm" (method) sperm (object) to woman (object) ,

OOP is a concept developed to take the stress out of programming, to take the manual labour out of programming and put the "art and engineering" into it.
Programming is not just about writing functional code now, but being able to come back to the code later, to add more functionality easily, make it more efficient e.t.c
You may not fully understand OOP till you have written over 2000 lines of code and your London bridge of spaghetti code starts falling down when you need to make a few additions or do some plumbing to your code.
When you finally get that experience, you'll hate procedural coding all your life.
But, paraphrasing Newton, he said "he stood on the shoudlers of giants see he could see farther than his peers.
Make all the effort to learn and use OOP now, so u'll be saved all the stress.
i'm still learning too.
Learning neva ends.
Re: Understanding Object Oriented Programming (OOP) by Nobody: 12:08am On Jul 23, 2007
Ade2kay is right.
Man (object) "has" sperm(object) and he "uses" a woman(object) to transfer the sperm to her through sex(method).


(has- I possess this
uses - I don't possess this, but i will interface with it.)


Now here is another example. This one shows inheritance and polymorphism.
We have a class called Animal.

(C++)

class Animal
{
public:
int age;
void breathe();
};


Every animal has an age and every animal breathes in oxygen and breathes out CO. This is a parent class. In other words, if we wanted to create a Cow class, we could polymorph it from the Animal class and the new child (or specialized) Cow class would inherit the attributes and methods from the parent class, which in this case are age and the breathe method.

class Cow::public Animal
{
public:
void moo();
void milkOut();
}


This is why we can say a cow is an animal. it would be wierd saying an animal is a cow. Logic doesn't work like that.

(is - I was made from this)

Now that we have a Cow class from the Animal class, we can create specialized methods and attributes that are akin to a cow like moo-ing and producing milk.
The above Cow class could also be created with this:

class Cow
{
public:
int age;
void breathe();
void moo();
void milkOut();
}


But when you are working on a huge project with lots of classes that all have the same fundamental attributes, then Polymorphism and Inheritance will definitely save you a lot of hassle.
Re: Understanding Object Oriented Programming (OOP) by chatykrew(m): 3:07pm On Jul 25, 2007
thanks we will keep the learning curve on.

take care
Re: Understanding Object Oriented Programming (OOP) by Seun(m): 4:46pm On Jul 25, 2007
I don't particularly like Object Oriented Programming. It is not very elegant in practice (Java specially).
I think you should only define new classes in cases where it makes your program easier to understand.
I find the overuse of inheritance particularly annoying: having to read 10 classes to understand one function!
Re: Understanding Object Oriented Programming (OOP) by Nobody: 6:29pm On Jul 25, 2007
@Seun

You're right, if you're working on something small, you don't need that many classes as a I said earlier. But when doing something big it helps keep your code organized, easily changeable and easily upgradeable.

The main advantage of OOP is modularity. Take for example a car. it is assembled from many parts, each part doing its own purpose: engine, tires, seats, etc. If the owner wants to change his engine and put something more powerful in there, all he has to do is remove the current engine and put a new one in. If the car wasn't actually assembled from parts and everything was just built into it like that (unremovable tires, unremovable engine, unremovable seats etc), every time the car has a fault it has to be given a complete overhaul because its just one huge pile of "everything". No parts can be easily exchanged. Same with a program. one class can be changed and upgraded without affecting much of the business of the other classes.

OOP is more of engineering than programming; it's for people who actually get paid to make proffessional software. I sometimes fashi it on my own unpaid programming endeavours.

(1) (Reply)

### HOT ### Get Free Software To Increase You Feedburner Subscribers / A Nairalander Designs A Software To Boast Entrepreneurship In Universities / How Many Tables OR Database Do You Use In Your Website?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 32
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.