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

How to catch any method called on an object in python?

I'm looking for a pythonic solution on how to store a method which is called on an object right inside the object. Because in python, if I want to catch for example the abs() method, I will overload this operator like: Catcher(object): def…
Peter Varo
  • 11,726
  • 7
  • 55
  • 77
20
votes
4 answers

Java - Initialize a HashMap of HashMaps

I am new to java and practicing by creating a simplistic NaiveBayes classifier. I am still new to object instantiation, and wonder what to do to initialize a HashMap of HashMaps. When inserting new observations into the classifier, I can create a…
David Williams
  • 8,388
  • 23
  • 83
  • 171
20
votes
10 answers

Why do we need abstract classes in C++?

I've just learned about polymorphism in my OOP Class and I'm having a hard time understanding how abstract base classes are useful. What is the purpose of an abstract class? What does defining an abstract base class provide that isn't provided by…
Yoshua Joo Bin
  • 517
  • 3
  • 6
  • 15
20
votes
6 answers

How to programmatically find public properties of a class from inside one of it's methods

I've got a class Foo with public and protected properties. Foo needs to have a non-static method, getPublicVars() that returns a list of all the public properties of Foo (this is just an example, I know from outside the Foo object calling…
Ray
  • 40,256
  • 21
  • 101
  • 138
20
votes
7 answers

OOD / OOP Etudes / Code exercises

I've been searching the web for some time now. I am looking for small sample exercises for OOD practice (& for some internal TDD workshops). If there is one single place, where this need is being served, please point me to it.. and close this…
Gishu
  • 134,492
  • 47
  • 225
  • 308
20
votes
6 answers

Extend interface to an abstract class

I have an interface (move) that should move some shapes. interface Move { move(); } abstract class Shape : Move class Circle : Shape class Square : Shape class Triangle : Shape My doubt is, I must have an interface which moves Shapes but only…
sok
  • 612
  • 2
  • 10
  • 24
20
votes
3 answers

private member accessible from other instances of the same class

I just noticed something that I've never realised before. It turns out that this class is valid in C#: class Foo { private string contents; public Foo(string str) { contents = str; } public void set(Foo other) { …
Oliver
  • 11,297
  • 18
  • 71
  • 121
20
votes
5 answers

DAO pattern and model objects

I have looked up a lot of information about the DAO pattern and I get the point of it. But I feel like most explainations aren't telling the whole story and by that I mean where would you actually use your DAO. So for example if I have a User class…
Tom
  • 613
  • 2
  • 6
  • 9
20
votes
6 answers

How to write our own marker interface in Java?

I know marker interface in java. It is used to define a specific behaviour about a class. For example, Serializable interface has the specific ability to store an object into byte stream and its reverse process. But I don't know where this specific…
Saravanan
  • 11,372
  • 43
  • 143
  • 213
20
votes
3 answers

Inherit class-level instance variables in Ruby?

I want a child class to inherit a class-level instance variable from its parent, but I can't seem to figure it out. Basically I'm looking for functionality like this: class Alpha class_instance_inheritable_accessor :foo # @foo = [1, 2,…
wmjbyatt
  • 686
  • 5
  • 15
20
votes
4 answers

How do I create a Perl class?

I am writing Perl classes to remove redundancies from scripts and since Perl has a lot of ways to make classes I keep having trouble making the classes properly. So does anyone have a best practice example of a class? The biggest question I have is…
kthakore
  • 1,566
  • 3
  • 17
  • 32
20
votes
4 answers

Good Object Oriented Class Design for collision detection in game development

I want to learn how to create good object-oriented (OO) design practice for collision between two objects situation in game development. Let's say I have a SpaceShip class and a Meteor class. When Meteor collide with the SpaceShip, the SpaceShip…
null
  • 8,669
  • 16
  • 68
  • 98
19
votes
3 answers

OO Javascript : Definitive explanation of variable scope

Can someone provide an explanation of variable scope in JS as it applies to objects, functions and closures?
javito
  • 1,529
  • 6
  • 16
  • 24
19
votes
12 answers

Does several levels of base classes slow down a class/struct in c++?

Does having several levels of base classes slow down a class? A derives B derives C derives D derives F derives G, ... Does multiple inheritance slow down a class?
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
19
votes
13 answers

Interface should not have properties?

My office colleague told me today that is bad practice to use properties in interfaces. He red that in some MSDN article(s), which I couldn't find (well I was trying few times on google, probably with wrong key words). He also told me that only…
Andrija
  • 14,037
  • 18
  • 60
  • 87