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
19
votes
5 answers

Pimpl idiom with inheritance

I want to use pimpl idiom with inheritance. Here is the base public class and its implementation class: class A { public: A(){pAImpl = new AImpl;}; void foo(){pAImpl->foo();}; private: AImpl* pAImpl; }; class AImpl { …
Igor
  • 26,650
  • 27
  • 89
  • 114
19
votes
4 answers

Initializing class instance variables in Ruby

I am working on a small rails app and have a problem with ruby's OOP model. I have the following simplified class structure. class Foo protected @bar = [] def self.add_bar(val) @bar += val end def self.get_bar @bar …
HalloDu
  • 907
  • 1
  • 7
  • 16
19
votes
1 answer

Object Oriented Design Practice Problems

I've been developing almost exclusively C-code for the past few years. I'm currently looking to brush up on my Object Oriented Design skills. Can anyone recommend any resources that have a decent set of short object-oriented design problems with…
DuneBug
  • 1,543
  • 4
  • 15
  • 28
19
votes
9 answers

Using the Single Responsibility Principle in the "real world"

I basically want to get an idea of the percentage of people who think it's reasonable to use the Single Responsibility Principle in real-world code and how many actually do. In Podcast #38 Joel talks about how useless this OOP principle is the real…
Thiru
  • 271
  • 2
  • 11
19
votes
6 answers

Difference between an instance of a class and a class representing an instance already?

I use Java as an example but this is more of a general OOP design related question. Lets take the IOExceptions in Java as an example. Why is there a class FileNotFoundException for example? Should not that be an instance of a IOException where the…
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
19
votes
30 answers

That A-Ha Moment for Understanding OO Design in C#

I've been studying C# for a couple of years, reading voraciously, even taking a few C# data access courses from Microsoft. I've also been reading books on OOP. I'm coding a web-based database application at work. While my job title is not…
GregD
  • 6,860
  • 5
  • 34
  • 61
19
votes
1 answer

Workbook on object oriented design (object model domain, system sequence diagrams, interaction diagrams)

Although I have a somewhat solid ground on object oriented theory and know how to build something as simple as a tetris / tic tac toe game in a "evolutive" design with no major trouble, I'd like to learn how to take the totally different approach of…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
19
votes
4 answers

Iterate over subclasses of a given class in a given module

In Python, given a module X and a class Y, how can I iterate or generate a list of all subclasses of Y that exist in module X?
Mark Roddy
19
votes
2 answers

Swift-Generics: "Cannot specialize non-generic type"

I try to implement object oriented code by using a generic protocol. Lets say I have two protocols protocol Executable: class { func execute() } protocol Dockable: class { associatedtype T func dock(object: T) } I've implemented a…
ObjectAlchemist
  • 1,109
  • 1
  • 9
  • 18
19
votes
1 answer

When trying to invoke def, I get: parameter 'self' unfilled

I'm trying to write a class to randomly pick a number of songs from a dictionary. The whole point of it is to be able to simply type DJ.chooseListing() for example to execute the random selection. Alas it gives me an error I can't really find…
Thom Ernst
  • 379
  • 1
  • 4
  • 15
19
votes
4 answers

Examples of 'Things' that are not Objects in Ruby

"Everything is an object" was one of the first things I learned about Ruby, but in Peter Cooper's Beginning Ruby: From Novice to Professional, it is mentioned that "almost everything in Ruby is an object". Can you give me some examples of things…
Yaser Sulaiman
  • 3,311
  • 2
  • 28
  • 25
19
votes
2 answers

Actor model vs object oriented model

I searched in the web for a long time and couldn't find the concrete disadvantages of object oriented model which are overcome in Actor model. Please help me with some pointers and explanations on it. Thanks in advance.
Suga Raj
  • 481
  • 3
  • 15
19
votes
8 answers

calling child methods from parent pointer with different child classes

I've a parent class with 2 or more child class deriving from it. The number of different child classes may increase in future as more requirements are presented, but they'll all adhere to base class scheme and will contain few unique methods of…
Abhinav Gauniyal
  • 7,034
  • 7
  • 50
  • 93
19
votes
8 answers

Why do almost all OO languages compile to bytecode?

Of the object-oriented languages I know, pretty much all but C++ and Objective-C compile to bytecode running on some sort of virtual machine. Why have so many different languages settled on compiling to bytecode, as opposed to machine code? Is it…
keiter
  • 3,534
  • 28
  • 38
19
votes
4 answers

What is the exact difference between 'Adapter' and 'Mediator" patterns?

I know that Adapter is a structural pattern and Mediator is a behavioral one. But as far I understood, what both of them are doing, is connecting two (or more) other classes which are potentially incompatible (not so maintainable) for direct…
1 2 3
99
100