Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
interview question

why we use object oriented programming and what is the uses of object oriented programming.
Posted
Updated 10-Feb-17 3:08am
v2
Comments
Mehdi Gholam 18-Nov-11 2:49am    
Not everybody uses object orientated programming, it depends on the user and the problem.
Sergey Alexandrovich Kryukov 18-Nov-11 3:00am    
Not only on that. Some are using non-OOP technologies, but many only pretend they are using OOP only because they write key words like "class", but in fact they do anything but OOP. I knew many examples of such thing, and first example I knew was a big commercial product.
--SA
Albert Holguin 18-Nov-11 13:31pm    
I've seen that as well... ugly...

Why? Because if you stick to the rules, it makes complex code easier to develop, more relieable, more maintainable, and generally better.

Because OOP insists that you think about what you expose to the outside world, it lets you change the implementation of an object without affecting any other code. (Encapsulation)
Because it allows you to have many different functions, all with the same name, all doing the same job, but on different data. (Polymorphism)
Because it lets you write generic code: which will work with a range of data, so you don't have to write basic stuff over, and over again. (Generics)
Because it lets you write a set of functions, then expand them in different direction without changing or copying them in any way. (Inheritance)

There are other reasons, but those are pretty good ones!
 
Share this answer
 
Comments
Mehdi Gholam 18-Nov-11 3:07am    
Comprehensive, 5'ed
Albert Holguin 18-Nov-11 13:30pm    
+5
Member 11228773 12-Nov-14 15:14pm    
very well explained.. 5*
Bad question, since it is rhetorical and contains the answer.

It wants to intimidate you by immediately restricting your thinking:

WHY - WE - USE.

Simply not polite, stupid and ridiculous.
The proper question should have been WHEN (not WHY), or WHY and WHY NOT.

What is the interviewer expecting here?
Someone throwing fireworks illuminating all the night of programming science while explain the beautifulness of OOP and why there shouldn't be anything else about that around the world ?!?

Do they know that the C++ STL is NOT (I repeat: is NOT) OOP ?
Do they know that there is almost no OOP into a lambda?
Do they know that OOP is just a technique, not a religion?

It is incredible how many stupidity is involved in selecting people.

What are they seeking for? Someone silently obeying to their god, or someone that is able to think?
 
Share this answer
 
Why to use OOP ?

Let's take a look before OOP concepts coming, there was "Procedural" programming which concist of designing a software as a bunch of functions and procedures verry welded.Thus Softwares becomes quickly complexe, hard to understand and to maintain.

The OOP introduced new concepts for looking to softwares design : real world Object concept.
This concept will come to produce softwares as seperated code modules which riseup decoupling and increases code re-usability.
A common use of decoupling in OOP is to polymorphically decouple the encapsulation.
For reusibility it is introduced by Inheritance and Generics concepts.
See Solution 1 to have a quick definition of Polymorphism, generics, inheritance and encapsualtion.

Hope this helps.
 
Share this answer
 
Comments
Emilio Garavaglia 19-Nov-11 13:50pm    
OOP Object concept is not "real world". Just a (in the sense of ONE OF) model of it. The concept of "separated module" does not require necessarilly OOP, and re-usability is not a direct consequence of OOP (a badly designed mess of entangled objects is all but reusable)
Generic programming is not OOP. It can be used in OOP, but it has its own definition, and does not necessarily relates to objects.

The most of these arguments belongs much more to the OOP mythology, than technology.
elgaabeb 19-Nov-11 19:52pm    
Verry interesting point of you but not really conventional.
Just one Question have you ever used procedural programming language???
I mentioned "real world" according to source of inspiration of this programming concepts.
We could never take a bad example as reference, you just said it it's BAD design !
I've never said that generic is OOP, Generic is litteral word which you could refer to adictionnary to see its meaning.
OOP is a concept of programming which increases reusibility when objects could be reused it's time worth!
OOP mythlogie ?? verry interesting! verry romantic!
Emilio Garavaglia 20-Nov-11 10:32am    
"have you ever used procedural programming language???"? Yes: C and FORTRAN, as I used LISP (functional) as I used COBOL, Smalltalk, C++, D etc.
And I programmed "objects" (in real OOP sense) with plain C, with proper usage of compilation separation and opaque types.
There are languages that are fundamental agnostic to the programming technique (C, C++ and D fall in this category) for which their standard library pushes a philosophy (iostream are OOP, containers are generic, ...)
There are languages (like C# or Java) that are created around a well defined programming technique (OOP, in that case, functinal for LISP etc.) for which every problem you want to solve must be solved through that only technique (even if not efficient at all). As a consequence, marketing was forced to push on that convincing abut a presumed "superiority" that -in fact- is not intrinsic as they want it top appear.
elgaabeb 21-Nov-11 4:31am    
Thax for your reply. I think we could discuss what you pointed out on a forum.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900