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

How to use class methods as callbacks

I have a class with methods that I want to use as callbacks. How can I pass them as arguments? Class MyClass { public function myMethod() { // How should these be called? $this->processSomething(this->myCallback); …
SmxCde
  • 5,053
  • 7
  • 25
  • 45
138
votes
8 answers

Why we should not use protected static in java

I was going through this question Is there a way to override class variables in Java?. The first comment with 122 upvotes was: If you ever see a protected static, run. Can anyone explain why is a protected static frowned upon?
Zeeshan
  • 11,851
  • 21
  • 73
  • 98
137
votes
6 answers

What does "S3 methods" mean in R?

Since I am fairly new to R, I do not know what the S3 methods and objects are. I found that there are S3 and S4 object systems, and some recommend to use S3 over S4 if possible (See Google's R Style Guide at…
jiggysoo
  • 1,498
  • 2
  • 10
  • 9
136
votes
14 answers

Why java.lang.Object is not abstract?

Possible Duplicate: Java: Rationale of the Object class not being declared abstract Why is the Object class, which is base class of 'em all in Java, not abstract? I've had this question for a really really long time and it is asked here purely…
Elister
  • 1,576
  • 2
  • 10
  • 14
136
votes
8 answers

Java: Static Class?

I have a class full of utility functions. Instantiating an instance of it makes no semantic sense, but I still want to call its methods. What is the best way to deal with this? Static class? Abstract?
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
135
votes
6 answers

When and why would you seal a class?

In C# and C++/CLI the keyword sealed (or NotInheritable in VB) is used to protect a class from any inheritance chance (the class will be non-inheritable). I know that one feature of object-oriented programming is inheritance and I feel that the use…
Aan
  • 12,247
  • 36
  • 89
  • 150
134
votes
10 answers

Mixin vs inheritance

What is the difference between a mixin and inheritance?
Johnd
  • 6,441
  • 9
  • 29
  • 22
134
votes
6 answers

Default visibility of class methods in PHP

I looked at the manual, but I can't seem to find the answer. What is the default visibility in PHP for methods without a visibility declaration? Does PHP have a package visibility like in Java? For example, in the following code, is go() public or…
Yada
  • 30,349
  • 24
  • 103
  • 144
133
votes
4 answers

Managing relationships in Laravel, adhering to the repository pattern

While creating an app in Laravel 4 after reading T. Otwell's book on good design patterns in Laravel I found myself creating repositories for every table on the application. I ended up with the following table structure: Students: id, name Courses:…
ehp
  • 1,689
  • 3
  • 14
  • 20
132
votes
11 answers

What is the exact problem with multiple inheritance?

I can see people asking all the time whether multiple inheritance should be included into the next version of C# or Java. C++ folks, who are fortunate enough to have this ability, say that this is like giving someone a rope to eventually hang…
Vlad Gudim
  • 23,397
  • 16
  • 69
  • 92
131
votes
14 answers

When should I use C++ private inheritance?

Unlike protected inheritance, C++ private inheritance found its way into mainstream C++ development. However, I still haven't found a good use for it. When do you guys use it?
Sasha
131
votes
10 answers

Should I use a class or dictionary?

I have a class that contains only fields and no methods, like this: class Request(object): def __init__(self, environ): self.environ = environ self.request_method = environ.get('REQUEST_METHOD', None) self.url_scheme =…
deamon
  • 89,107
  • 111
  • 320
  • 448
131
votes
1 answer

Plotting with seaborn using the matplotlib object-oriented interface

I strongly prefer using matplotlib in OOP style: f, axarr = plt.subplots(2, sharex=True) axarr[0].plot(...) axarr[1].plot(...) This makes it easier to keep track of multiple figures and subplots. Question: How to use seaborn this way? Or, how to…
Frozen Flame
  • 3,135
  • 2
  • 23
  • 35
131
votes
7 answers

Overloaded method selection based on the parameter's real type

I'm experimenting with this code: interface Callee { public void foo(Object o); public void foo(String s); public void foo(Integer i); } class CalleeImpl implements Callee public void foo(Object o) { logger.debug("foo(Object…
Sergey Mikhanov
  • 8,880
  • 9
  • 44
  • 54
131
votes
6 answers

How can I call the 'base implementation' of an overridden virtual method?

Given the following code, is there a way I can call class A's version of method X? class A { virtual void X() { Console.WriteLine("x"); } } class B : A { override void X() { Console.WriteLine("y"); } } class Program { static void Main() { …
mackenir
  • 10,801
  • 16
  • 68
  • 100