Questions tagged [oop]

Object-oriented programming is a programming paradigm using "objects": an encapsulation consisting of data fields and methods together with their interactions.

OOP

Object-oriented programming (OOP) is a programming paradigm using the concept of objects. These encapsulates data which is organized in the form of fields (often known as attributes) and code, in the form of procedures (often known as methods). Methods can access and often modify attributes of the object with which they are associated. In OOP, computer programs are designed based on having objects interacting among each other.

OOP includes features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. Many modern programming languages now support OOP.

FAQs

  1. Interface vs Base class
  2. Prefer composition over inheritance?
  3. Polymorphism vs Overriding vs Overloading
  4. What is a class in PHP?
  5. What's the point of OOP?
  6. Inheritance vs. Aggregation
  7. Object-orientation in C
  8. What are the differences between struct and class in C++?
  9. Interface vs Abstract Class (general OO)
  10. What's the difference between a method and a function?
  11. What is the difference between an interface and abstract class?
  12. What is the difference between an abstract function and a virtual function?
  13. What is the difference between public, private, and protected?
  14. Functional programming vs Object Oriented programming
  15. Difference between abstraction and encapsulation?
  16. How do you design object oriented projects?
  17. Difference Between Cohesion and Coupling
  18. prototype based vs. class based inheritance
  19. Aspect Oriented Programming vs. Object-Oriented Programming
  20. What is polymorphism, what is it for, and how is it used?
61861 questions
253
votes
4 answers

Clone Object without reference javascript

I have a big object with much data. And i want to clone this in other variable. When i set some param of the instance B has the same result in the original object: var obj = {a: 25, b: 50, c: 75}; var A = obj; var B = obj; A.a = 30; B.a =…
Enzo
  • 4,111
  • 4
  • 21
  • 33
251
votes
7 answers

OOP vs Functional Programming vs Procedural

What are the differences between these programming paradigms, and are they better suited to particular problems or do any use-cases favour one over the others? Architecture examples appreciated!
249
votes
17 answers

Difference between Inheritance and Composition

Are Composition and Inheritance the same? If I want to implement the composition pattern, how can I do that in Java?
gmhk
  • 15,598
  • 27
  • 89
  • 112
246
votes
9 answers

How to call a parent method from child class in javascript?

I've spent the last couple of hours trying to find a solution to my problem but it seems to be hopeless. Basically I need to know how to call a parent method from a child class. All the stuff that I've tried so far ends up in either not working or…
YemSalat
  • 19,986
  • 13
  • 44
  • 51
245
votes
8 answers

Separating class code into a header and cpp file

I am confused on how to separate implementation and declarations code of a simple class into a new header and cpp file. For example, how would I separate the code for the following class? class A2DD { private: int gx; int gy; public: …
drdrdr
  • 2,788
  • 4
  • 17
  • 16
244
votes
18 answers

What does 'low in coupling and high in cohesion' mean

I have problems understanding the statement low in coupling and high in cohesion. I have googled and read a lot about this, but still finding it hard to understand. To what I understand is High cohesion means, that we should have classes that are…
user1315906
  • 3,374
  • 8
  • 30
  • 43
243
votes
15 answers

What is the point of interfaces in PHP?

Interfaces allow you to create code which defines the methods of classes that implement it. You cannot however add any code to those methods. Abstract classes allow you to do the same thing, along with adding code to the method. Now if you can…
mk.
  • 26,076
  • 13
  • 38
  • 41
243
votes
23 answers

How do you design object oriented projects?

I'm working on a large project (for me) which will have many classes and will need to be extensible, but I'm not sure how to plan out my program and how the classes need to interact. I took an OOD course a few semesters back and learned a lot from…
Victor
  • 5,697
  • 6
  • 34
  • 41
242
votes
7 answers

Iterate over object attributes in python

I have a python object with several attributes and methods. I want to iterate over object attributes. class my_python_obj(object): attr1='a' attr2='b' attr3='c' def method1(self, etc, etc): #Statements I want to generate…
Pablo Mescher
  • 26,057
  • 6
  • 30
  • 33
240
votes
4 answers

How to mark a class as Deprecated?

Possible Duplicate: How do I mark a method as Obsolete/Deprecated? - C# How do you mark a class as deprecated? I do not want to use a class any more in my project, but do not want to delete it before a period of 2 weeks.
Mister Dev
  • 10,021
  • 12
  • 41
  • 33
239
votes
16 answers

Are getters and setters poor design? Contradictory advice seen

I'm currently working on a simple game in Java with several different modes. I've extended a main Game class to put the main logic within the other classes. Despite this, the main game class is still pretty hefty. After taking a quick look at my…
Mike B
  • 12,768
  • 20
  • 83
  • 109
236
votes
13 answers

Thou shalt not inherit from std::vector

Ok, this is really difficult to confess, but I do have a strong temptation at the moment to inherit from std::vector. I need about 10 customized algorithms for vector and I want them to be directly members of the vector. But naturally I want also…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
233
votes
4 answers

prototype based vs. class based inheritance

In JavaScript, every object is at the same time an instance and a class. To do inheritance, you can use any object instance as a prototype. In Python, C++, etc.. there are classes, and instances, as separate concepts. In order to do inheritance, you…
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
233
votes
15 answers

What are the advantages of using getters and setters instead of functions or simply public fields in PHP?

I'm not a PHP developer, so I'm wondering what the advantages and disadvantages are in PHP to using explicit getter/setters, in a pure OOP style, with private fields (the way I like): class MyClass { private $firstField; private…
Mark
  • 67,098
  • 47
  • 117
  • 162
232
votes
5 answers

C++ equivalent of java's instanceof

What is the preferred method to achieve the C++ equivalent of java's instanceof?
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395