Questions tagged [object-oriented-design]

Object-oriented design is the process of planning a system of interacting objects for the purpose of solving a software problem.

Filter by
Sorted by
Tagged with
78 votes
10 answers
15k views

How functional programming achieves "No runtime exceptions"

How does a functional programming language, such as Elm, achieve "No runtime exceptions"? Coming from an OOP background, runtime exceptions have been part of whatever framework that is based ...
user avatar
  • 879
1 vote
3 answers
588 views

How is inheritance possible with immutability?

The title almost sums it up but let me be example-led and clearer. Assuming we have a class: class T: def goto(self, value): print('go') And a second inheriting class: class A(T): def ...
user avatar
6 votes
1 answer
651 views

Why would it be considered bad practice if a concrete class inherits from only one Mixin?

I'm referring to "Fluent Python" by Luciano Ramalho. In chapter 12, there's a section "Coping with Multiple Inheritance" where the author suggests a few best practices, such as: ...
user avatar
  • 476
2 votes
1 answer
122 views

How do refactor a code which picks service based on null checks on field?

I have a bean that has around 10+ fields and it may grow till 30 odd fields. The bean is a contract between applications to share data over an HTTP call. Basically, a downstream application will set ...
user avatar
2 votes
2 answers
402 views

The most popular definition for LSP seems very contradictory

Out of the 5 SOLID principles, I find LSP to be the most confusing one. The most popular description of this principle is simply "A subclass must be replaceable with it's base class without ...
user avatar
3 votes
2 answers
284 views

Most expressive way of allocating member data, per Stroustrup

I was watching a lecture by Bjarne Stroustrup from 2014, on "The Essence of C++". About halfway through he rather forcefully recommends not using new, delete, or pointers for class member ...
user avatar
1 vote
2 answers
1k views

Is a python `abstract property` that returns an abstract class an example of the Factory Pattern?

I need to document my design, in particular, the design patterns used, and would like to use the standard terminology. From Refactoring Guru, "Factory Method defines a method, which should be ...
user avatar
  • 137
10 votes
5 answers
3k views

C++ "Zero Overhead Principle" in practice

As an exercise in code architecture, I was writing a C++ wrapper for a window library called GLFW3. In this library, when a window's X button is pressed, you can register a callback that reacts to ...
user avatar
  • 111
7 votes
3 answers
332 views

Breaking up a class with too many responsibilities

I'm looking for advice on my specific problem, how to break up a class, Basket, that has too many responsibilities. Currently, it does three things: Keeps track of the products in the basket: ...
user avatar
1 vote
3 answers
119 views

Constructing an Object from Multiple Services

I have an object that contains several dozens of properties. A portion of property values come from Service A, others from Service B, and the remaining from Service C. This object is a flat model that ...
user avatar
  • 165
-1 votes
2 answers
150 views

Decoupling 2 Tightly Coupled Classes, Basket and Discount

I have two tightly coupled classes Basket and Discount. Basket is responsible for keeping track of the items in a shopping basket, keeping track of any discount codes applied, and calculating the ...
user avatar
1 vote
1 answer
72 views

Resolve concrete object in constructor from a given id

I have the following class export class Agent { constructor(modelName: string) { this.shape = app.gallery.getModel(modelName); ... } randomMethod() { ... // using app for ...
user avatar
1 vote
2 answers
81 views

Separate responsibilities when public methods depend on other public methods in same class?

Recently I hit something like the following setup in our codebase, and I'm wondering if there's a preferred way to do it, to achieve the cleanest separation. public class FileLoader { public ...
user avatar
0 votes
3 answers
95 views

Class Model - optional grouping, referencing the parent or the grandparent

Possibly my problem already has a solution, but I couldn't find it as I don't know the correct terminology. Essentially I have a class called 'Item'. Usually this item is grouped into Groups (N:1 ...
user avatar
  • 111
0 votes
0 answers
198 views

TaskManager class design

We implemented a TaskManager class for this purpose: execute a number of tasks asynchronously (off the UI thread) one after the other. Basically, this class includes a queue of tasks and the functions ...
user avatar
  • 169
7 votes
2 answers
805 views

Suggested OO Design Pattern for a Query Builder

Essentially, I'm building a Query Builder (in C#, if that's relevant) which has this sort of interface, exposing more statically typed functions as the query gets more refined. AnimalQueryBuilder - ...
user avatar
  • 179
6 votes
2 answers
949 views

Does OOP overemphasize the importance of noun and thus put action/verb in the less importance position ? [closed]

Steve yegge wrote an article called "Execution in the Kingdom of Nouns" back in 2006, 14 years later I still find the points he made valid. For example, "Action is what gives life its ...
user avatar
1 vote
4 answers
1k views

Where should transform method to convert from one class object to another class object should live in Java?

I have 2 POJO classes, DatabaseRecord and MyCustomRecord. In my service logic, I wanted to convert the object of type DatabaseRecord to object of type MyCustomRecord. The code for converting should be ...
user avatar
  • 161
-1 votes
3 answers
355 views

Preventing presentation layer from directly accessing repositories?

I'm trying to design my application in line with the "onion architecture" principles, and have something like the following: HospitalController (depends on IHospitalService) \ --- ...
user avatar
  • 1,356
2 votes
2 answers
102 views

Action objects VS handle/service-methods

a short question: class ItemActionObject { private final Object moreParameters; private final Object otherDependencies; private final Item item; public ItemActionObject(Item item, ...
user avatar
-1 votes
1 answer
221 views

Split object into multiple objects while keeping reasonable performance

I'm using C# but the problem could also be with Java. I have an object in the flow that is muted for setting up some properties during the flow of the program. Let say public class Person { public ...
user avatar
  • 109
19 votes
9 answers
4k views

Which object should have the method?

I am trying to create an object model for a user and a chatroom. I'm stuck on where to place certain functionality when the objects collaborate. At the moment all the functionality for the User is ...
user avatar
1 vote
3 answers
2k views

Advantages of strategy design pattern versus simple if-else

I am not clear on what advantage does strategy pattern offers over simple if-else. Example of poor code //poor code that we all can agree is not the way to go ----- main class ----- String ...
user avatar
0 votes
2 answers
106 views

Where to place methods that consume multiple object collections

We've been battling over where certain methods should live within our domain model, so looking for some adice and reasoning as to where they should go. Say we have a Project object now that Project ...
user avatar
  • 149
1 vote
1 answer
218 views

Strategy Design Pattern vs Inheritance

I have to write a code where i have send some data (call it List of cases) using one of two integration tools (Jitterbit, Mulesoft), with possibility of adding more tools in future. Integration tool ...
user avatar
0 votes
0 answers
179 views

value-based function dispatch

Problem to solve I have a method parse_doc that should dynamically determine a parsing function to parse document_id based on the value of the document_id string: # list of files that may have ...
user avatar
  • 117
3 votes
3 answers
2k views

Entities vs. Services in domain driven design (DDD)

I wanted to get some feedback on the design of a chat application I recently developed. The application is written in PHP, but the language probably isn't important here. The main components are User, ...
user avatar
  • 179
-1 votes
3 answers
187 views

Specialization and LSP violation?

I have Document and ExternalDocument classes in my system, where ExternalDocument extends Document. The main distinction is that ExternalDocument holds onto externalDocumentId and externalEventId data ...
user avatar
  • 321
-1 votes
3 answers
133 views

Difference between update a property and fire an event

It seems to me that update a property is always an 'event' and that all you can do with an event handler can be done in the property let/set routine. And, in my limited experience, I never needed to ...
user avatar
  • 211
0 votes
4 answers
184 views

How does Object Oriented System or Decomposition supports reuse?

The 1 logic is that due to inheritance. But, except that how does Object Oriented Systems helps in reusability? I have read this article below. https://www.drdobbs.com/a-realistic-look-at-object-...
user avatar
  • 127
96 votes
9 answers
18k views

Is it the correct practice to keep more than 10 years old spaghetti legacy code untouched without refactoring at all in big product development?

I have been in two software product houses for three years in a row. The first is a small company maintaining a fairly small management system with a monolithic legacy code base (almost twenty years). ...
user avatar
  • 1,487
2 votes
2 answers
236 views

Composition vs Aggregation: is this a "hidden my dependencies" case?

I have been thinking about this for a while and could not get to a conclusion. I need to convert a object to another (that will end up serialized as XML). Both objects have many fields, let's have an ...
user avatar
1 vote
2 answers
171 views

How to implement rich domain model without referencing other objects?

I have some doubts about having rich domain model without having other entity objects inside it. Let's imagine that we have a product feed with no more than 10 products. Each product is made by some ...
user avatar
4 votes
1 answer
232 views

What do you call the interface design error that consists in splitting two public methods that should be called together?

Consider a poorly-designed interface in which there are two functions (say foo() and bar()) that can be called independently, but in order to get some expected behavior (or in order to keep the object ...
user avatar
  • 151
1 vote
3 answers
371 views

Design with subclasses being aggregates of classes implementing interfaces

I have modelled a class structure, where subclasses Rectangle and Circle inherit from an abstract superclass Figure. All subclasses share an interface IGeometry that provides for getArea() and ...
user avatar
  • 29
1 vote
4 answers
1k views

Loose coupling in Python

While I know this is the tight coupling example: class User: def __init__(self): pass def get_status(self): api_client = APIClient() status = api_client....
user avatar
  • 231
0 votes
1 answer
320 views

Have the same logic in two different class hierarchies

I have the following class hierarchies abstract class Base<T> { abstract T getRelevantType(); } class A : Base<AType> { AType getRelevantType() } class B : Base<...
user avatar
  • 119
3 votes
1 answer
162 views

How choose between functions or objects

I've seen different approaches and it's not clear to me which one is the correct one. Some dev use lots of small, very specific objects and use to compone them is some way to achieve their goal. ...
user avatar
  • 211
5 votes
6 answers
2k views

How to modify object properties?

I've recently read a great article about unit testing. There was an example of a bad method which is not well designed. It looks like this public static string GetTimeOfDay() { DateTime time = ...
user avatar
  • 231
0 votes
2 answers
2k views

Unit testing private methods

preface: I know this topic has been asked about a lot on here in the past. Hopefully I will make it clear that I've read a fair amount of the questions/answers on the topic, and other literature, too. ...
user avatar
  • 3,128
3 votes
1 answer
206 views

Is the class stereotype implicit in an UML class diagram ? Should it be specified?

Commonly I see class diagrams where there is no <<class>> stereotype. Others where there is the common <<interface>> and others with some interesting ones as <<shape>&...
user avatar
0 votes
1 answer
133 views

Why is the UNIX / FP style of smaller function composition not common?

TL;DR Why is the UNIX / functional style of composing and injecting smaller functions so much rarer than the Beck/Fowler/Bob refactor-to-objects style when it comes to writing maintainable, "...
user avatar
5 votes
1 answer
214 views

Real-world scenarios for protected inheritance

C++ supports protected inheritance: A class can derive from a base class B in a way that the "outside" world doesn't see that class "as a B" but the class itself and it's derived ...
user avatar
4 votes
5 answers
294 views

How to fix a pair of tightly coupled classes that store references to each other?

I have the following situation: class User { public Thing curThing; } //each thing can only belong to one user at a time //And vice versa class Thing { ...
user avatar
  • 49
-1 votes
1 answer
177 views

Making a GUI for receiving/checking user input - how to arrange GUI and validation checks

Sorry if my question sounds general, I'm new to GUI and frontend/backend ideas and all that (mostly I just do scripts for math hw and such) but I make it more specific here. I have a program that runs ...
user avatar
-2 votes
2 answers
71 views

How to design a flexible multi-criteria prioritization?

Let's assume that we have a set of valid results, ex. Fruits: "Apple, Banana, Kiwi, Pear, ...". (In reality, it’s not fruits but complex objects) Now we need to pick the best result ...
user avatar
  • 393
0 votes
1 answer
288 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 ...
user avatar
  • 103
2 votes
1 answer
345 views

Efficient way to store "item" objects in a simple game

I am developing a simple text-based game. In this game, the user is able to collect items and store them in an inventory. My question is: how should I organize the internal structure of my game so ...
user avatar
  • 131
0 votes
1 answer
127 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 ...
user avatar
28 votes
6 answers
8k 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. ...
user avatar
  • 586

1 2 3
4
5
33