Questions tagged [object-oriented]

A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner

Filter by
Sorted by
Tagged with
0
votes
1answer
61 views

Could a getState() method in a Caretaker violates Memento Pattern?

After looking at several examples of implementation of Momento on the internet, I wondered whether it is correct or not to retrieve the status of Originator, being much more accurate, whether it is ...
0
votes
2answers
157 views

How to visualise Inheritance and Polymorphism?

I want to make diagrams that explain how Inheritance and Polymorphism work conceptually. Assume that we have a Cat class that inherits from the Animal class. The way that I can think of a Cat object ...
2
votes
2answers
94 views

Builder Pattern: Is there any advantage of having instance variables + product reference instead of just product reference?

Consider the product class: class Car { private String color; private String model_num; //getters and setters for the above fields } Consider builder class 1: class CarBuilder1 { private ...
0
votes
2answers
137 views

Retrieve all objects of the same specific class from an abstract class

I have an abstract class called ProjectItem and I have 2 specific classes. One of them is called Task and the other is called Deliverable. I have to put all the ProjectItems inside a list, which I did,...
0
votes
0answers
79 views

Using for_each instead of iterators to avoid iterator invalidation

I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
2
votes
3answers
567 views

Can writing Object-Orientated Code in a Functional style improve performance?

Given a scenario where you have consecutive setters or a series of events where an object is modified, can it be more performant to instead write code in a way where a new state is returned rather ...
0
votes
4answers
195 views

C# refactoring with inheritance

I have two classes which contains almost same method. How can I refactor this with inheriting one class by other class. class A{ public void run(){ // task 1 // task 2 // task 3 } ...
1
vote
4answers
116 views

Removing a base class from its according collection OOP

Lets say i have a zoo class, with a bunch of collections. The collections are giraffes, elephants, tigers etc. All animal types derive from the same interface or base class, lets call it IAnimal. So ...
-2
votes
1answer
92 views

Simple circular dependency between three classes

I have this basic design with a circular dependency. Is there any solution for this? The problem is that a Machine cannot be created if a Model for that Team has been submitted.
1
vote
2answers
180 views

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface?

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface (if such implementation is even possible)?
0
votes
2answers
253 views

Terminology: Classes that contain only methods [closed]

I am studying the programming language Kotlin, and I just came across the idea of a Data Class. I have a background in Java programming where classes can have fields and methods. I have heard ...
1
vote
3answers
138 views

Can two unique messages share the same name in OOP?

In this question, the asker of the question shows the following example (no Polymorphism is used): circle1.draw(); rectangle1.draw(); And the highest voted answer says the following: In your example,...
2
votes
1answer
90 views

What is the design of libraries like cairo and OpenGL called?

I'm not a software engineer, so sorry if the question is elementary. Usually, functions provided by libraries written in C receive a handle from the calling program. This handle directly (if it's a ...
3
votes
3answers
215 views

Decoupling and Command Pattern

I am working on some project to learn how to make bigger and better software (multiplayer game) and I found a problem about having in my code a design pattern Command Pattern and anti-pattern God ...
0
votes
1answer
83 views

Are inheritance, abstraction and polymorphism regarded as association in OOP?

In the realm of OOP, inheritance, abstraction and polymorphism are basic concepts of the paradigm. On top of that, there also have the concept called "associations" which I understand is ...
24
votes
6answers
6k views

Visitor Pattern: what's the point of the `accept` method?

I'm trying to fully understand the visitor pattern. What I've learnt so far (correct me if I'm wrong) is: It's about adding operations to classes, without modifying the source code of those classes. ...
0
votes
2answers
87 views

Can other behavioral OOP design patterns be expressed in terms of Strategy and Template Method Patterns for behaviour parameterization?

I'm studying OOP design patterns in a solution-oriented way which I mean not concentrating just one pattern but with a comparative analysis like their combined or hybrid usages and equivalents in ...
-5
votes
1answer
151 views

Use Case Diagram for Vending machine

I want to create a use case diagram for a vending machine which has the following states: Accepts coins of 1,5,10,25 Cents Allow user to select products Coke(25), Pepsi(35), Soda(45) Allow user to ...
1
vote
4answers
197 views

Is thinking of an OOP object as a “small program” a good analogy?

I have read that we can think of an OOP object as a "small program" that send messages to other "small programs" (objects), but I am not sure if this is a good analogy. One reason ...
1
vote
5answers
344 views

Why OOP languages use the syntax “object.function()” to send a message?

In C++ and Java and many other OOP languages, in order to send a message to an object, you have to use the object.function() syntax, for example: myCar.start(); // send the start() message to the ...
1
vote
1answer
84 views

Design Patterns: Factory Pattern Vs. getInstance Inside Abstract Class

I'm working on an app where we need to use different authentication flows depending on how the user is accessing the app. I want to make sure that there is only one instance of the authentication ...
0
votes
1answer
77 views

Extension of classes - Where to put behaviour - How much direct-access is allowed

At this point i would exclude the inheritance.... So the question is about more like extend into a seperate class or into the class which should be extended, both play in the composition-league. So ...
1
vote
1answer
62 views

Object oriented service best practice when changing a methods behavior for given context?

I expect this is a common problem and/or pattern question for beginners to OOP. Somehow I find myself wondering again and wasn't able to find a decent answer. So at the risk of creating a dupe... What ...
3
votes
2answers
314 views

What does “common interface” mean in OOP?

I have seen the term "common interface" used a lot while reading books about OOP. For example, the book The Essence of Object-Oriented Programming with Java and UML says the following: ...
-4
votes
1answer
38 views

Dynamically assign attributes to objects from outside

In python the following code works perfectly fine. class Table: pass table = Table() table.fruits = ["apple", "orange"] But as soon as we check it out with some kind of ...
1
vote
4answers
273 views

Is checking the type of a variable antithetical to OOP?

As an example, in PHP you can run gettype($myVariable); to obtain the type of a variable $myVariable. Is such functionality antithetical to OOP principles?
7
votes
4answers
614 views

Why does C++ have classes?

The title is deceptive; the question is really "why does C++ have classes and not only structs?" Often, people ask why C++ has structs if they are functionally equivalent to classes. The answer is (...
0
votes
1answer
89 views

what is the correct OOP way to read/write binary data if meta information of how data is encoded is stored inside data itself?

I have a Buffer which wraps a stream of binary data. The first byte indicates order, either big endian or little endian, which is needed to unpack the data. class FooBuffer implements Buffer is ...
0
votes
0answers
21 views

How to support alternative behaviour at the end of a pipeline when the new behaviour is decided at the beginning?

Let's assume we have a few loosely coupled components that form a pipeline. At the end is an file generating component. A new requirement comes in that requires an parallel alternative behaviour for ...
4
votes
2answers
189 views

How to design a SOLID pipeline with different inputs

I regularly have the situation that I have some complex logic that I break into steps. For example an import of an Excel file where I need to apply some logic or a complex calculation that I break ...
0
votes
3answers
150 views

OOD vs MVC; Live Objects vs Everything in Database

How to make memory-efficient code, but still have all the possible code nicely encapsulated ? I have a feeling that the OO (object oriented) approach is more intuitive and the code is nicely ...
1
vote
2answers
40 views

What does this statement about implementing forwarding methods of components mean?

I can't wrap my head around this statement here: One common drawback of using composition instead of inheritance is that methods being provided by individual components may have to be ...
1
vote
1answer
63 views

Can a GoF Builder implementation be considered valid without an explicit getProduct()?

For studying purpose, I've tried to create a simple PHP implementation of Builder GoF (not the Joshua Bloch's one) inspired on this slide. The main goal of this example is to encapsulate the ...
1
vote
1answer
62 views

How to design a class holding information about a relationship between two interchangable objects

I'd like to design a class that holds comparison results about to objects. Given I have a class Thing and that Thing has a bunch of properties. Now I have an engine that compares Thing instances (...
1
vote
4answers
207 views

OOP design: how to find one Subclass object in an array of Superclass objects?

Say I have a Group object which maintains a list of its Members: private $members; Now the class Member has a range of subclasses such as OrdinaryMember and GroupLeader. Every group has precisely ...
0
votes
1answer
79 views

How to define values dependant on the derived type?

My base class must provide an interface to get a value that is dependent solely on the type of the derived class. I can think of two ways of implementing this: Solution A, virtual functions: class ...
3
votes
1answer
85 views

Should a service object be transient or persistent?

In a typical server software design, business logic will generally invoke "services" (such as a database or web service). When I design such a system, I tend to think of each service as a singleton ...
3
votes
2answers
219 views

OOP - How to identify inheritance abusage?

In looking for a simple heuristic to see when inheritance can be abused, I came up with the following hypothesis: If subclass B overrides method foo, but does not call base.foo(), it seems like ...
1
vote
1answer
43 views

Inheriting DBModels and UI Models from Domain Models

I made a pretty simple CRUD API to store customers and some related information in a database. My customer has 20 properties like Name, Telephone etc. that are all stored in an anemic domain model. My ...
2
votes
1answer
60 views

How to determine whether the postcondition of overridden methods is weaker or stronger if there is no return value?

To reiterate the question - what does it mean to have a weaker or stronger postcondition when overriding a method that only does side effects with another one that only does side effects? P.S. What ...
0
votes
1answer
107 views

Object Oriented Design of Callback Methods

Assume that there is a library and it provides an interface to its users in order to callback them. Users implement this interface and receive notifications from the library. Let's say, ICallback is ...
2
votes
2answers
135 views

How can I improve this design to achieve a more loosely coupled system and better testability?

My question I built an inverted pendulum on an Arduino using C (ie. everything was done procedurally). I'm trying to self study application design and would like to refactor my code into a more OO ...
3
votes
3answers
139 views

What is meant by “Polymorphism is the ability of an object to take on many forms”?

Based on many tutorials that I have read, the following is the definition of Polymorphism: Polymorphism is the ability of an object to take on many forms Now let's assume that we have an Animal ...
1
vote
6answers
330 views

In what ways is Polymorphism used (other than in arrays)?

I have read many tutorials on Polymorphism and all of them show examples of Polymorphism used in arrays, for example you would have an Animal (parent class) array, and its elements are Cat and Dog and ...
0
votes
1answer
116 views

Mixing IoC container use with “poor mans” DI

I'm finding the use of IoC containers to be quite the shift in my application design, and its for the better. I'm using a framework called injector that aims to mimic (albeit not entirely) the Guice ...
1
vote
3answers
128 views

Best way to Model Classes associated with other Classes?

I'm trying to make a sports stats app in Java/Android + Realm. I have the following classes: Season Player Matches I would like the Season to contain a "list" of all the players that played that ...
-10
votes
1answer
69 views

Find design issues via a class diagram? [duplicate]

Given a class diagram , how can we find design issues in it. I am not talking about the relationships it should be representing as they exist in the real world but i am talking about design issues ...
0
votes
3answers
162 views

How to find design defects by using a class diagram? [closed]

What are the design defects that can be spotted by using a class diagram, and how? I am not concerned about syntactical/ representational defects, but in things like the following: Do the classes/...
-3
votes
1answer
64 views

How to know if the UML class diagram design is good (well-planned) or not in java

I've learned the UML recently and I am trying to build a MonsterDuel system. However, there are a lot of classes in this project, and I am confused about the abstract class and its usage. Now, I have ...
19
votes
10answers
6k views

What is polymorphism if you can already have methods that are the same defined in different types?

I often read definitions for Polymorphism such as the following: Polymorphism is the ability to have objects of different types understanding the same message But the above definition also apply ...

1
2
3 4 5
61