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

Beginner Array of Objects Confusion

I am having trouble understanding what is actually happening when I declare the array in the following code. class Type1 { } class Type2 extends Type1 { public void method2() { } } class Test { public static void main(String[] args)…
Lindstorm
  • 890
  • 2
  • 7
  • 22
20
votes
4 answers

Calling a subclass method from a superclass

Preface: This is in the context of a Rails application. The question, however, is specific to Ruby. Let's say I have a Media object. class Media < ActiveRecord::Base end I've extended it in a few subclasses: class Image < Media def show #…
Shaun
  • 4,789
  • 3
  • 22
  • 27
20
votes
1 answer

What are the best practices for combining marshmallow schema definitions and OO in Python?

Assume a simple schema defined in marshmallow class AddressSchema(Schema): street=fields.String(required=True) city=fields.String(required=True) country=fields.String(default='USA') class PersonSchema(Schema): …
Chris Mungall
  • 629
  • 5
  • 13
20
votes
1 answer

Kotlin: 'This type has a constructor and thus must be initialized here', but no constructor is declared

Recently started with Kotlin According to Kotlin docs, there can be one primary constructor and one or more secondary constructor. I don't understand why I see this error Since class test has no primary constructor. This works fine: open class test…
Shafayat Alam
  • 702
  • 1
  • 14
  • 32
20
votes
5 answers

ES6 Classes - Updating Static Properties

I am trying to figure out alternative ways to set a static (or class) property an ES6 Class and then change it after new instances of the class are created. For example, lets say I have a class called Geo, and I need a static property called all…
Jared
  • 631
  • 1
  • 7
  • 19
20
votes
3 answers

Calling a private instance method from a class method in Ruby

Can I create a private instance method that can be called by a class method? class Foo def initialize(n) @n = n end private # or protected? def plus(n) @n += n end end class Foo def Foo.bar(my_instance, n) …
user4812
  • 5,942
  • 9
  • 30
  • 35
20
votes
6 answers

Are there any rules for OOP?

Recently I heard that there are 9 rules for OOP(Java). I know only four as Abstraction, Polymorphism, Inheritance and Encapsulation. Are there any more rules for OOP?
Viki
  • 251
  • 1
  • 4
  • 7
20
votes
8 answers

How can I add an event listener for all events in javascript without listing them individually?

I'd like to accomplish the following code using a wildcard (that I don't think exists?) myObject.element = document.getElementsByClassName('js-myObject'); myObject.element.addEventListener('click',…
Ken Sherman
  • 279
  • 1
  • 2
  • 9
20
votes
1 answer

Assign external function to class variable in Python

I am trying to assign a function defined elsewhere to a class variable so I can later call it in one of the methods of the instance, like this: from module import my_func class Bar(object): func = my_func def run(self): self.func() …
astrojuanlu
  • 6,744
  • 8
  • 45
  • 105
20
votes
7 answers

Diamond inheritance (C++)

I know that having diamond inheritance is considered bad practice. However, I have 2 cases in which I feel that diamond inheritance could fit very nicely. I want to ask, would you recommend me to use diamond inheritance in these cases, or is there…
Igor
  • 26,650
  • 27
  • 89
  • 114
20
votes
9 answers

PHP get_called_class() alternative

I've got an Abstract PHP superclass, which contains code that needs to know which subclass its running under. class Foo { static function _get_class_name() { return get_called_class(); //works in PHP 5.3.*, but not in PHP 5.2.* …
Kenneth Ballenegger
  • 2,970
  • 2
  • 19
  • 25
20
votes
2 answers

Codeigniter: when to use a model vs library?

I've starting using Codeigniter for a project recently (few months ago) but its getting a little out of hand with a bunch of models that need to interact with each other and I was wondering if I should be creating a library instead? In my case, I…
wag2639
  • 2,523
  • 5
  • 25
  • 30
20
votes
12 answers

the use of private keyword

I am new to programming. I am learning Java now, there is something I am not really sure, that the use of private. Why programmer set the variable as private then write , getter and setter to access it. Why not put everything in public since we use…
LAT
  • 291
  • 1
  • 3
  • 5
20
votes
4 answers

How to pass arbitrary arguments to a flask blueprint?

I have a flask api which I have wrapped up in an object. Doing this has made unit testing a breeze, because I can instantiate the api with a variety of different settings depending on whether it is in production, test, or whatehaveyou. I am now…
melchoir55
  • 6,842
  • 7
  • 60
  • 106
20
votes
3 answers

Use multiple classes in other namespaces

If I have some php classes inside a namespace com\test and want to import all of them into another php file how can do that? use com\test\ClassA use com\test\ClassB ... use com\test\* give me syntax error.
xdevel2000
  • 20,780
  • 41
  • 129
  • 196