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
1 vote
1 answer
94 views

The notion of configurable strategies

I'm designing an algorithm that matches entries based on some notion of "proximity" (for the sake of discussion, assume we're matching floats). Furthermore: The input is a scalar and a ...
user avatar
  • 223
1 vote
3 answers
69 views

Multi type HTML dropdown conversion to the corresponding C# object type

Note: This is a contrived example I came up with to illustrate what I'm after as simply as possible. I have an HTML report with a single dropdown box at the top that lets the user select (or filter) ...
user avatar
1 vote
2 answers
78 views

Java OOP Philosophy/Design: Mutable classes

I do know that the best practice these days is to model immutable classes in Java. An ex: below // It makes sense to model this in an immmutable fashion class 2DPoint { private int x; private int ...
user avatar
  • 119
0 votes
0 answers
32 views

Dispatch based on ENUM/String value

I've the following classes: TypeAHandler, TypeBHandler,... Each handler can turnOn or turnOff a list of object ids (e.g. handler for type A calls microservice, handler for Type B modifies DB entry). I'...
user avatar
  • 149
0 votes
1 answer
64 views

Bean objects vs "functional" objects

I'm wondering how to choose between those "patterns" - please forgive me if I don't use the right terms - when having to deal with complex object coming from the front I want to process. ...
user avatar
  • 217
16 votes
7 answers
3k views

Where should interfaces be used?

One thing I've long struggled with being able to grasp properly is, when designing a program in an object-oriented language, where and how should explicitly named/defined interfaces be added? In ...
user avatar
0 votes
1 answer
75 views

Validation in a simple DDD example

I'm doing a simple project that represents a CI Pipeline in a low scale. So I'm trying to model "the best way possible" to practice DDD. Basically I have the following information: ...
user avatar
-1 votes
2 answers
241 views

Is it bad practice to have too many direct subclasses?

Let's say we have an undo/redo system and we have a superclass storing an object that should later form a tree of the attributes that can be undone/redone. This would require every class that should ...
user avatar
  • 29
0 votes
3 answers
90 views

Decoupling command and receiver in command pattern

I'm writing a simulation of a car that can receive commands and act on them and I'm trying to implement it using the command pattern. class Car { move() { console.log('move'); } } interface ...
user avatar
0 votes
2 answers
89 views

Should I instantiate the state objects of a finite state machine?

I have a class hierarchy with a base State class, several inheriting classes each named after their relevant state, and an FSM class that contains all the states in a particular state machine as well ...
user avatar
  • 329
0 votes
0 answers
18 views

Mapping data that were input to one module, to input to of module

Lets say we have typical trivial CRUD app: user sends data controller catch the request and map it controller sends data to service for processing structure: - api - request - ...
user avatar
  • 231
1 vote
1 answer
104 views

Side effect as a common object seems like a bad pattern

Given an auction system, there are several ways to apply a discount to the transaction's final amount, e.g. Special discount for a given seller discount for a given buyer Discount for a specific ...
user avatar
0 votes
1 answer
98 views

is there a two-way (bidirectional) observer pattern?

I have two classes. "System" and "Bluetooth". I want to have a really loose coherency between these two classes as they should be able to exist or not without depending on each ...
user avatar
0 votes
1 answer
82 views

Verbs in Use Case name "Create User" [closed]

I'm struggling on how to name classes for use cases. Because I know that is "bad" to use verbs in classes names(Uncle Bob) but at the same time names of use case classes should explain what ...
user avatar
2 votes
1 answer
169 views

Best way to refactor service with too many dependencies

We are creating the backend for a web app using a sort of layered architecture. The service layer is supposed to handle the business logic and passing data to the repositories. This service layer is ...
user avatar
  • 29
14 votes
11 answers
5k views

Encapsulation dilemma: should age operations depend on external dates outside the object?

A few days ago I stumbled upon a silly "problem" that made me reflect about encapsulation and OOP design. I have a class called User that has a method hasMinimumLegalAge() that checks if the ...
user avatar
-1 votes
1 answer
73 views

Design: Designing a Status Tracking Tool

We have a robust set of micro-services available. For simplicity, let us call the services S1 S2 S3 S4 S5 For simplicity, think of the flow to be this. S1 -> performs step1 (start step) S2 -> ...
user avatar
2 votes
5 answers
343 views

Do db calls in constructors lead to more DRY code?

It recently came to my attention that its best practice to avoid database calls in constructors. I feel like this means you end up repeating unnecessary code, thus the code is less DRY? For example, ...
user avatar
2 votes
1 answer
369 views

Difference between `Class.X` and `Class.getX()`?

Might be a silly question or something I might have just messed up in my head but here we go... I saw a code example of someone using getPos() in their own class to retrieve the current position of an ...
user avatar
0 votes
1 answer
152 views

How can I split tightly coupled code in an OOP language?

So I've a class that is some kind of wrapper of a state machine for a multipart upload and it's database writes/reads. Everytime something is uploaded via REST basically the following happens ...
user avatar
  • 149
9 votes
5 answers
784 views

Today I wrote "tests" for the testing code. Was it the right thing? Is it a smell?

My application has big integration with the database. Classes that use the database are very crucial for the system, so I write small unit tests for classes that I call Repository. The reason behind ...
user avatar
  • 705
4 votes
3 answers
254 views

Class Constructor that Takes Two Arguments of the Same Interface - But Order Matters

I'm getting ready to release a feature to production tomorrow & feel I have misdesigned said feature. I'll try to explain my scenario clearly. I'm looking for alternative design suggestions to ...
user avatar
49 votes
7 answers
9k views

Why is inheritance bad in a Person-Student model?

I've just started learning about Inheritance vs Composition and it's kind of tricky for me to get my head around it for some reason. I have these classes: Person class Person { public string Name {...
user avatar
4 votes
3 answers
468 views

Are there any legitimate use cases for protected visibility?

Protected visibility in languages like C++, Java or PHP is a strange beast: it makes fields and methods accessible in subclasses, but not in code completely outside the class. It strikes me as ...
user avatar
2 votes
4 answers
235 views

What is the middle ground between understanding basic OOP concepts (inheritance, composition, aggregation) and design/architectural patterns?

I've been coding in python for about 6 years now. I am proficient enough to understand a good amount of the language features. When I look into source code for a number of libraries such as pandas or ...
user avatar
  • 213
-1 votes
2 answers
120 views

Is having a big class always considered bad OOP design? [closed]

So I have this distributed game im working on(for some time now). A part of the world is considered a Chunk object. This object is composed of many other objects/components that are necessary and a ...
user avatar
  • 7
1 vote
1 answer
131 views

In an effort to design small aggregates, have you tried making every aggregate the aggregate root? You'd need to refactor afterwards, of course

I'm currently designing a DDD system, and it is a reference implementation. The reference is a big ball of mud. I'm finding myself spending a fair amount of time determining aggregate roots and the ...
user avatar
0 votes
3 answers
144 views

Composite Pattern get part of the tree

I use java and I have structure with a class that contains id, title and perhaps some children of the same class. So I decided to use the composite pattern. I need to have a method getChildren() that ...
user avatar
2 votes
2 answers
136 views

Type checking, multiple functions and how to overcome function parameter names?

I have a search function. This function takes 4 different parameters that can be either a list of strings or a string. For each parameter, if it's a string I convert it to a list of strings. def ...
user avatar
  • 149
3 votes
2 answers
134 views

Where do methods in class diagrams come from?

In a class diagram, how do I know what methods to add? I’m not sure what the connection is between methods and other (i.e. Activity and User Case) diagrams. My guess is that methods can come from ...
user avatar
  • 139
2 votes
1 answer
101 views

How to solve reacting to events from different sources which have a common source

I find it difficult to explain but I'll give it a try. I have a module structure where the modules can fire events and other modules respond to them. As you can see, B & C are listening to events ...
user avatar
5 votes
3 answers
235 views

Better to store references to an object, or to store its ID and retrieve it with a hashMap

Given the classes: public class SocialNetwork { private final Map<String, User> users; ... } public class User { private final String user; private final LinkedList<String>...
user avatar
  • 61
1 vote
2 answers
90 views

Difference between Front Controller and Mediator patterns [closed]

I was reading about these patterns and noticed that they seem to be basically the same, but in different contexts? If that's the case, why isn't Front Controller just considered as a Mediator pattern ...
user avatar
5 votes
2 answers
982 views

Design classes to model 3D scanned faces of ancient Greek/Roman sculptures: is multiple inheritance a good design solution?

I would like to deepen the topic of multiple inheritance using Python and I usually find examples that are too simple. I love art and I imagined the following problem and I want to understand if ...
user avatar
  • 380
2 votes
2 answers
118 views

Procedural configuration code to object oriented code

Lets say we have an Webserver-Framework and a Database-Framework, and now i want to configure that Webserver and the Database, then it could look like the following class Start { public static ...
user avatar
2 votes
3 answers
236 views

OOPS Relationship between Soccer Field and Soccer Player

I am trying to design a simple Soccer game. To keep things simple, I am having a SoccerField to represent the field and a Player class to represent an individual. A SoccerField will contain a list of ...
user avatar
1 vote
3 answers
214 views

What behaviours to put in and out of a class

Let's say I have a class modeling some kind of object, for example a graph (in the graph theory sense). I will have the graph structure and data inside the class, but what about other more complex ...
user avatar
1 vote
1 answer
127 views

State Pattern when the Behavior in Object of Type A is Dependent on the State of the Object of Type B

I have used the state pattern for my web application where a user can be in one of three states: activated, required_activation and suspended. I have created 3 states classes as given below (source is ...
user avatar
  • 137
-1 votes
1 answer
137 views

Why is `replace(dataclass, **kwargs)` a function, and not a member?

Imagine a simple data class: @dataclass class Settings: m: int s: str old = Settings(m=10, s="ten") It feels normal to write new = old.replace(m=1), but we have to write new = replace(...
user avatar
  • 334
3 votes
1 answer
192 views

Best Practice for Populating Objects in Python

So I am pulling data (list of JSON) from an API and want to parse it into Python objects. However the JSON objects of my list returned from my API need to be transformed a bit to fit into my object. I ...
user avatar
-2 votes
3 answers
79 views

Design consideration-To add or not to add a related variable in a class

I need something clarified. I have been having a discussion with someone and we have conflicting arguments. Hence, I came here to ask looking for your insights. Say we have to implement our own stack ...
user avatar
0 votes
0 answers
71 views

Splitting nested entities keeping invariant within aggregates

I'm currently developing message imap-based module in crm app and i'm trying to connect dots using ddd principals. I've started with three main entities, all bound under Account Aggregate: Account - ...
user avatar
0 votes
1 answer
153 views

Different Aggregate Root States in Domain Driven Design

I have read the Domain Modeling Made Functional book. In the book, the author model the Order in 3 different states: Unvalidated Validated Priced The 3 states have different properties. But it's ...
user avatar
0 votes
1 answer
64 views

Interface design for container that holds different instances derived from a common type

I'm currently designing an interface for a container that is supposed to store references of different instances that derived from a common supertype. An analogy of it would be as following: Suppose ...
user avatar
2 votes
2 answers
237 views

Is it a code smell to have two different implementations of the builder design pattern, for the same model?

Shoutout to David Arno for teaching me about the builder design pattern via this thread! I have since used that pattern althroughout the code base to abstract out creating models from data stores, ...
user avatar
1 vote
2 answers
144 views

Connecting classes by passing method references

I am trying to find a good way of allowing two objects that are separated by a intermediate object to communicate while keeping the architecture loosely coupled. A solution I have developed is to pass ...
user avatar
  • 21
0 votes
2 answers
151 views

How best to deal with growing polymorphic interfaces?

Consider the following scenario in an object-oriented environment. Sample code is in C++, but it could be any OO language. A software must control an external device, say a TV. From the start you know ...
user avatar
3 votes
4 answers
397 views

Is it a bad practice to have an interface method to tell whether it can handle an object?

interface Resolver { boolean canResolve(SomeInput input); SomeOutput resolve(SomeInput input); } public static void main(String[] args) { List<Resolver> resolvers = ...; ...
user avatar
2 votes
3 answers
460 views

What we called this design pattern and it is same as strategy pattern?

abstract class BaseService { public void doSomething(); } class AService extends BaseService { public void doSomething(){ // Do something... } } class BService extends BaseService { ...
user avatar
0 votes
0 answers
61 views

State Pattern: Changing object behavior based on more than one field and consistency between their values and state value

I'm Trying to learn about State Pattern. In most of State Pattern examples that I have seen, methods of class change their behavior based on just one field (I mean before applying State Pattern and I'...
user avatar

1
2 3 4 5
33