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
20
votes
1 answer

Why is IEnumerable necessary when there is IEnumerator?

Disclaimer: I understand the difference between IEnumerable and IEnumerator and how to use both. This is not a duplicate of this or this. This is more of a design question - since IEnumerator already encapsulates all the necessary…
KFL
  • 17,162
  • 17
  • 65
  • 89
20
votes
15 answers

Misused design patterns

Are there, in the canonical Gang of Four list, any design patterns that you often find misused, misunderstood or overused (other than the highly debated Singleton)? In other words, is there a design pattern you would advise to think twice before…
Federico A. Ramponi
  • 46,145
  • 29
  • 109
  • 133
20
votes
2 answers

Memory layout in Javascript - data-oriented vs object-oriented design

Coming from a background of C/C++, memory layout of objects with regards to reducing cache misses is something that is crucial especially when working on consoles. Data-oriented design is often favored over object-oriented design, in order to help…
smg
  • 1,133
  • 1
  • 11
  • 22
20
votes
1 answer

Is there a way to create JavaScript objects that behave like C++ RValues?

I'm a C++ programmer who recently landed on the JavaScript world; now I'm trying to apply some of the dessign patterns of C++ to JavaScript for the sake of my understanding and mental health. AFAIK, the following codes are kind of equivalent in C++…
PaperBirdMaster
  • 12,806
  • 9
  • 48
  • 94
20
votes
4 answers

How to avoid Anemic Domain Models and maintain Separation of Concerns?

It seems that the decision to make your objects fully cognizant of their roles within the system, and still avoid having too many dependencies within the domain model on the database, and service layers? For example: Say that I've got an entity with…
Adam Ness
  • 6,224
  • 4
  • 27
  • 39
20
votes
4 answers

JavaScript Inheritance with Prototypes -- 'constructor' property?

I've seen a lot of stuff like this, and am looking for the proper solution to basic JavaScript inheritance: function Food(){} // Food constructor (class) function Bread(){} // Bread constructor (class) var basicFood = new Food(); // Food…
ChaseMoskal
  • 7,151
  • 5
  • 37
  • 50
20
votes
5 answers

Class - variable declaration

When the declaration of a PHP class variable we cannot perform any expressions, e.g.: class A { $a = 10 + 5; } only we can just provide constants e.g.: class A { $a = 100; } Can anybody knows why its like that?
akhil.cs
  • 691
  • 1
  • 5
  • 12
20
votes
3 answers

What is a good name for class which creates factories? (FooFactoryFactory sounds silly imo)

I don't remember exactly is it a common pattern but I have a class (Factory Method pattern) which has method for creating other classes (Abstract Factory pattern) depending on enum parameter: public class FooFactoryFactory { public FooFactory…
Roman
  • 64,384
  • 92
  • 238
  • 332
20
votes
5 answers

Is it acceptable to return unmodifiableList or should I return array?

I have method List getFoos () which gets the data from remote server and returns it. Of course, user shouldn't change number of items of the list because he'll get data not synchronized with data on the server (and if he want change number of…
Roman
  • 64,384
  • 92
  • 238
  • 332
20
votes
4 answers

Domain driven design and transactions in Spring environment

I used to design my application around anemic domain model, so I had many repository object, which were injected to the big, fat, transaction-aware service layer. This pattern is called Transaction script. It's not considered a good practice since…
semberal
  • 2,204
  • 1
  • 21
  • 21
20
votes
9 answers

Method Overloading with different return type

I am want to dig in that whether it is an ambiguity or an extra feature that is provided: public class Foo { public int Bar(){ //code } public string Bar(int a){ //code } } Any one having any experience with…
Adil Abbasi
  • 3,161
  • 1
  • 40
  • 35
20
votes
6 answers

Using Command Design pattern

Can anyone explain with a simple example the Command Pattern? I tried searching on the internet, but I got confused.
RKCY
  • 4,095
  • 14
  • 61
  • 97
20
votes
3 answers

C# Extend class by adding properties

Is it possible in C# to extend a class not by adding only functions but properties. Ex: i have a standard DLL library I am relying on and the vendor does not want to modify it. Already throughout the code I have used the DataCell class extensively…
Vans S
  • 1,743
  • 3
  • 21
  • 36
20
votes
2 answers

Access Outer Class this instance

how do we access outer class this instance: eg in Class A { Class B { this.helloB(); (A's this).hello() } } how do we access A's this instance in Java
sachin
  • 1,376
  • 2
  • 15
  • 37
20
votes
17 answers

For C/C++, When is it beneficial not to use Object Oriented Programming?

I find myself always trying to fit everything into the OOP methodology, when I'm coding in C/C++. But I realize that I don't always have to force everything into this mold. What are some pros/cons for using the OOP methodology versus not? I'm more…
Luis B
  • 1,684
  • 3
  • 15
  • 25