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

Constructors in JavaScript objects

Can JavaScript classes/objects have constructors? How are they created?
Ali
  • 261,656
  • 265
  • 575
  • 769
404
votes
8 answers

What's wrong with overridable method calls in constructors?

I have a Wicket page class that sets the page title depending on the result of an abstract method. public abstract class BasicPage extends WebPage { public BasicPage() { add(new Label("title", getTitle())); } protected abstract…
deamon
  • 89,107
  • 111
  • 320
  • 448
394
votes
3 answers

How can I call a function within a class?

I have this code which calculates the distance between two coordinates. The two functions are both within the same class. However, how do I call the function distToPoint in the function isNear? class Coordinates: def distToPoint(self, p): …
Steven
  • 4,193
  • 3
  • 17
  • 11
394
votes
31 answers

When should you use 'friend' in C++?

I have been reading through the C++ FAQ and was curious about the friend declaration. I personally have never used it, however I am interested in exploring the language. What is a good example of using friend? Reading the FAQ a bit longer I like…
roo
  • 7,106
  • 8
  • 39
  • 45
377
votes
8 answers

How do I implement interfaces in python?

public interface IInterface { void show(); } public class MyClass : IInterface { #region IInterface Members public void show() { Console.WriteLine("Hello World!"); } #endregion } How do I implement Python…
Pratik Deoghare
  • 35,497
  • 30
  • 100
  • 146
377
votes
21 answers

Polymorphism vs Overriding vs Overloading

In terms of Java, when someone asks: what is polymorphism? Would overloading or overriding be an acceptable answer? I think there is a bit more to it than that. IF you had a abstract base class that defined a method with no implementation, and…
Brian G
  • 53,704
  • 58
  • 125
  • 140
375
votes
10 answers

How do I copy items from list to list without foreach?

How do I transfer the items contained in one List to another in C# without using foreach?
ratty
  • 13,216
  • 29
  • 75
  • 108
370
votes
11 answers

Interface or an Abstract Class: which one to use?

Please explain when I should use a PHP interface and when I should use an abstract class? How I can change my abstract class in to an interface?
user220758
358
votes
17 answers

When should I use "this" in a class?

I know that this refers to a current object. But I do not know when I really need to use it. For example, will be there any difference if I use x instead of this.x in some of the methods? May be x will refer to a variable which is local for the…
Roman
  • 124,451
  • 167
  • 349
  • 456
355
votes
8 answers

Use of alloc init instead of new

Learning Objective-C and reading sample code, I notice that objects are usually created using this method: SomeObject *myObject = [[SomeObject alloc] init]; instead of: SomeObject *myObject = [SomeObject new]; Is there a reason for this, as I have…
willc2
  • 38,991
  • 25
  • 88
  • 99
350
votes
6 answers

Why are unnamed namespaces used and what are their benefits?

I just joined a new C++ software project and I'm trying to understand the design. The project makes frequent use of unnamed namespaces. For example, something like this may occur in a class definition file: // newusertype.cc namespace { const…
Scottie T
  • 11,729
  • 10
  • 45
  • 59
349
votes
11 answers

Calling parent class __init__ with multiple inheritance, what's the right way?

Say I have a multiple inheritance scenario: class A(object): # code for A here class B(object): # code for B here class C(A, B): def __init__(self): # What's the right code to write here to ensure # A.__init__ and…
Adam Parkin
  • 17,891
  • 17
  • 66
  • 87
348
votes
19 answers

What is the difference between private and protected members of C++ classes?

What is the difference between private and protected members in C++ classes? I understand from best practice conventions that variables and functions which are not called outside the class should be made private—but looking at my MFC project, MFC…
Konrad
  • 39,751
  • 32
  • 78
  • 114
345
votes
4 answers

How can I create a copy of an object in Python?

I would like to create a copy of an object. I want the new object to possess all properties of the old object (values of the fields). But I want to have independent objects. So, if I change values of the fields of the new object, the old object…
Roman
  • 124,451
  • 167
  • 349
  • 456
345
votes
16 answers

What is the difference between loose coupling and tight coupling in the object oriented paradigm?

Can any one describe the exact difference between loose coupling and tight coupling in Object oriented paradigm?
Jim
  • 4,639
  • 5
  • 27
  • 31