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
1540
votes
8 answers

What are the differences between type() and isinstance()?

What are the differences between these two code snippets? Using type: import types if type(a) is types.DictType: do_something() if type(b) in types.StringTypes: do_something_else() Using isinstance: if isinstance(a, dict): …
abbot
  • 27,408
  • 6
  • 54
  • 57
1505
votes
33 answers

What is the difference between a field and a property?

In C#, what makes a field different from a property, and when should a field be used instead of a property?
Anonymous
1464
votes
12 answers

Naming Classes - How to avoid calling everything a "Manager"?

A long time ago I have read an article (I believe a blog entry) which put me on the "right" track on naming objects: Be very very scrupulous about naming things in your program. For example if my application was (as a typical business app) handling…
froh42
  • 5,190
  • 6
  • 30
  • 42
1319
votes
18 answers

What is a mixin and why is it useful?

In Programming Python, Mark Lutz mentions the term mixin. I am from a C/C++/C# background and I have not heard the term before. What is a mixin? Reading between the lines of this example (which I have linked to because it is quite long), I am…
TarkaDaal
  • 18,798
  • 7
  • 34
  • 51
1313
votes
26 answers

What is the purpose of the `self` parameter? Why is it needed?

Consider this example: class MyClass: def func(self, name): self.name = name I know that self refers to the specific instance of MyClass. But why must func explicitly include self as a parameter? Why do we need to use self in the…
richzilla
  • 40,440
  • 14
  • 56
  • 86
1257
votes
27 answers

When should you use a class vs a struct in C++?

In what scenarios is it better to use a struct vs a class in C++?
Alan Hinchcliffe
  • 12,862
  • 3
  • 18
  • 11
1216
votes
35 answers

What is an example of the Liskov Substitution Principle?

I have heard that the Liskov Substitution Principle (LSP) is a fundamental principle of object oriented design. What is it and what are some examples of its use?
1185
votes
14 answers

Usage of __slots__?

What is the purpose of __slots__ in Python — especially with respect to when I would want to use it, and when not?
Jeb
  • 15,939
  • 6
  • 34
  • 37
1144
votes
29 answers

Does functional programming replace GoF design patterns?

Since I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative languages. One article I found makes a fairly strong…
Juliet
  • 80,494
  • 45
  • 196
  • 228
1131
votes
16 answers

What is the difference between public, private, and protected?

When and why should I use public, private, and protected functions and variables inside a class? What is the difference between them? Examples: // Public public $variable; public function doSomething() { // ... } // Private private…
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
1124
votes
8 answers

What is the difference between old style and new style classes in Python?

What is the difference between old style and new style classes in Python? When should I use one or the other?
readonly
  • 343,444
  • 107
  • 203
  • 205
1039
votes
22 answers

How to get a JavaScript object's class?

I created a JavaScript object, but how I can determine the class of that object? I want something similar to Java's .getClass() method.
DNB5brims
  • 29,344
  • 50
  • 131
  • 195
966
votes
18 answers

What do __init__ and self do in Python?

I'm learning the Python programming language and I've came across something I don't fully understand. In a method like: def method(self, blah): def __init__(?): .... .... What does self do? What is it meant to be? Is it…
GUIDED BOMB
914
votes
33 answers

What does it mean to "program to an interface"?

I have seen this mentioned a few times and I am not clear on what it means. When and why would you do this? I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly. Is it just so if…
Damien
  • 13,927
  • 14
  • 55
  • 88
882
votes
21 answers

Monad in plain English? (For the OOP programmer with no FP background)

In terms that an OOP programmer would understand (without any functional programming background), what is a monad? What problem does it solve and what are the most common places it's used? Update To clarify the kind of understanding I was looking…
user65663