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
122
votes
16 answers

What is the difference between an interface and a class, and why I should use an interface when I can implement the methods directly in the class?

I am aware that this is a very basic question, but an interviewer asked me in a very trick way and I was helpless :( I know only material or theoretical definition for an interface and also implemented it in many projects I worked on. But I really…
Jasmine
  • 5,186
  • 16
  • 62
  • 114
121
votes
5 answers

Amazon Interview Question: Design an OO parking lot

Design an OO parking lot. What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking. The lot has 3 different types of parking: regular, handicapped and compact. Thanks!
burnt1ce
  • 14,387
  • 33
  • 102
  • 162
121
votes
9 answers

What is the purpose of python's inner classes?

Python's inner/nested classes confuse me. Is there something that can't be accomplished without them? If so, what is that thing?
Geo
  • 93,257
  • 117
  • 344
  • 520
121
votes
7 answers

What is the rationale behind having companion objects in Scala?

Is there a case where a companion object (singleton) for a class is needed? Why would I want to create a class, say Foo and also create a companion object for it?
Rahul
  • 12,886
  • 13
  • 57
  • 62
121
votes
8 answers

Where and how is the term used WRAPPER in programming, what does it help to do?

I come across software developers using the term of creating Wrappers of other classes or APIs or even some codes, this is a term used by experienced Software Programmers So any idea what do they mean by it; e.g. a simple question; we got two types…
Basit Anwer
  • 6,742
  • 7
  • 45
  • 88
121
votes
16 answers

Why can't I overload constructors in PHP?

I have abandoned all hope of ever being able to overload my constructors in PHP, so what I'd really like to know is why. Is there even a reason for it? Does it create inherently bad code? Is it widely accepted language design to not allow it, or are…
tom
  • 2,236
  • 2
  • 18
  • 26
120
votes
12 answers

Is there an alternative to bastard injection? (AKA poor man's injection via default constructor)

I most commonly am tempted to use "bastard injection" in a few cases. When I have a "proper" dependency-injection constructor: public class ThingMaker { ... public ThingMaker(IThingSource source){ _source = source; } But then,…
Patrick Szalapski
  • 8,738
  • 11
  • 67
  • 129
120
votes
7 answers

Sorting objects by property values

How to implement the following scenario using Javascript only: Create a car object with properties (top speed, brand, etc.) Sort a list of cars ordered by those properties
Constructor
  • 1,225
  • 2
  • 9
  • 3
120
votes
3 answers

C# : assign data to properties via constructor vs. instantiating

Supposing I have an Album class : public class Album { public string Name {get; set;} public string Artist {get; set;} public int Year {get; set;} public Album() { } public Album(string name, string artist, int year) …
VasileF
  • 2,856
  • 2
  • 23
  • 36
119
votes
5 answers

Javascript dynamically invoke object method from string

Can I dynamically call an object method having the method name as a string? I would imagine it like this: var FooClass = function() { this.smile = function() {}; } var method = "smile"; var foo = new FooClass(); // I want to run smile on the…
Mikulas Dite
  • 7,790
  • 9
  • 59
  • 99
117
votes
8 answers

Mediator Vs Observer Object-Oriented Design Patterns

I have been reading the Gang Of Four, in order to solve some of my problems and came across the Mediator pattern. I had earlier used Observer in my projects for making some GUI application. I am a bit confused as I do not find great difference…
AnotherDeveloper
  • 2,161
  • 2
  • 23
  • 27
117
votes
5 answers

simple explanation PHP OOP vs Procedural?

I would like to learn PHP and want to get an Idea about OOP and Procedural. I read some other blogs and tutorials about OOP vs Procedural but I still can't understand the approach. OOP vs Procedural Which I should learn? What is the difference in…
Pennf0lio
  • 3,888
  • 8
  • 46
  • 70
116
votes
6 answers

How to define interfaces in Dart?

In Java, I might have an interface IsSilly and one or more concrete types that implement it: public interface IsSilly { public void makePeopleLaugh(); } public class Clown implements IsSilly { @Override public void makePeopleLaugh() { …
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
116
votes
7 answers

Object vs Class vs Function

I was wondering - what's the difference between JavaScript objects, classes and functions? Am I right in thinking that classes and functions are types of objects? And what distinguishes a class from a function? Or are they really the same thing,…
Sean Bone
  • 3,368
  • 7
  • 31
  • 47
115
votes
13 answers

Inner class within Interface

Is it possible to create an inner class within an interface? If it is possible why would we want to create an inner class like that since we are not going to create any interface objects? Do these inner classes help in any development process?
gmhk
  • 15,598
  • 27
  • 89
  • 112