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
3 answers

Is a deep nested Dictionary an antipattern?

I have a structure that can be very easily represented using a three-deep nested dictionary, like so private static Dictionary>> PrerenderedTemplates; Where the structure might be used something…
Iain Fraser
  • 6,578
  • 8
  • 43
  • 68
19
votes
3 answers

In a @try-@catch-@finally block, is it good use finally or to continue normally?

This is a simple Objective-C question. When you use a @trythe work flow can run in 2 ways If some NSException appear, the code immediately jump to @catch block and than to @finally If not, finish to run the @try block and than run @finally So,…
Rodrigo
  • 11,909
  • 23
  • 68
  • 101
19
votes
4 answers

Dynamically call Class with variable number of parameters in the constructor

I know that it is possible to call a function with a variable number of parameters with call_user_func_array() found here -> http://php.net/manual/en/function.call-user-func-array.php . What I want to do is nearly identical, but instead of a…
bmarti44
  • 1,247
  • 2
  • 14
  • 22
19
votes
6 answers

Private nested static class - Good or bad practice?

Would it be considered a bad practice to nest a private static class inside of a non-static class? public class Outer { private static class Inner { } } The idea here is that all instances of 'Outer' would share access to the static…
Sean Thoman
  • 7,429
  • 6
  • 56
  • 103
19
votes
8 answers

what's the difference between inheritance and polymorphism?

can you give me a simple example of inheritance and polymorphism, so it could be fully clear and understandable? using C# would make it more clear, as I already learned it. P.S: the tutors, books we've got are in native language, (arabic) sorry if…
Obzajd
  • 283
  • 1
  • 2
  • 8
19
votes
5 answers

Instantiate an object without calling its constructor in PHP

To restore the state of an object which has been persisted, I'd like to create an empty instance of the class, without calling its constructor, to later set the properties with Reflection. The only way I found, which is the way Doctrine does, is to…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
19
votes
4 answers

Basic Scala OOP question - pass by reference?

I'm a little stumped at how silly this problem is and have a serious mindblank, but I thought I might ask anyway. I have an object Foo, with several fields. I want a method that can change any of its fields depending on which one is passed in as a…
Dominic Bou-Samra
  • 14,799
  • 26
  • 100
  • 156
19
votes
11 answers

Is OO design's strength in semantics or encapsulation?

Object-oriented design (OOD) combines data and its methods. This, as far as I can see, achieves two great things: it provides encapsulation (so I don't care what data there is, only how I get values I want) and semantics (it relates the data…
Phil H
  • 19,928
  • 7
  • 68
  • 105
19
votes
7 answers

Independent getter/setter methods, or combined?

While working on a project, I've been making some changes and browsing around existing framework API docs for insight. While perusing the Kohana docs, I noticed that the getters/setters of any given class are typically combined: public function…
Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
19
votes
3 answers

Should Domain Model Classes always depend on primitives?

Halfway through Architecture Patterns with Python, I have two questions about how should the Domain Model Classes be structured and instantiated. Assume on my Domain Model I have the class DepthMap: class DepthMap: def __init__(self, map:…
19
votes
5 answers

What is the opposite of OOP?

I started in High School learning java and python and I guess I just always learned OOP and nothing else my question is What are the other programming paradigms or types of programming languages beside OOP?
if_zero_equals_one
  • 1,716
  • 4
  • 17
  • 30
19
votes
3 answers

Delphi - Create class from a string

I got code like this name := 'Foo'; If name = 'Foo' then result := TFoo.Create else if name = 'Bar' then result := TBar.Create else if name = 'FooFoo' then result := TFooFoo.Create; Is there a way just to do result := $name.create or some…
Wizzard
  • 12,582
  • 22
  • 68
  • 101
19
votes
5 answers

How can Polymorphism replace an if-else statement inside of a loop?

How can polymorphism replace an if-else statement or Switch inside of a loop? In particular can it always replace an if-else? Most of the if-thens I use inside of loops are arithmetic comparisons. This question is spawned from this question. int…
WolfmanDragon
  • 7,851
  • 14
  • 49
  • 61
19
votes
5 answers

Java Reflection: get instances of a given class found by entering its name?

Is it possible to get all instances of a class by entering this class's name as a string? Something like this? var instances = Reflection.findClass("com.someone.MyClass").getInstances(); Any feedback is appreciated. Thanks.
Tom
  • 8,536
  • 31
  • 133
  • 232
19
votes
7 answers

$this keyword and compact function

In some contexts, we can use an array($this, 'variable') syntax, to refer to object properties. Why doesn't compact(array($this, 'variable')) work? Is there a way to work around this? class someclass { $result = 'something'; public…
Buddy
  • 1,808
  • 3
  • 19
  • 28
1 2 3
99
100