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 votes
2 answers
92 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
  • 11
0 votes
3 answers
85 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
84 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
0 votes
1 answer
98 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
83 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
78 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
131 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
71 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
341 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
368 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
149 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
  • 141
9 votes
5 answers
758 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
  • 695
4 votes
3 answers
248 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
458 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
231 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
116 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
104 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
127 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
134 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
133 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
223 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
79 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
964 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
  • 374
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
231 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
124 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
131 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
179 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
62 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
128 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
63 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
230 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
141 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
150 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
379 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
411 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
60 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 vote
1 answer
176 views

Not sure what to call this "builder" I created

I have written some code in Katalon Studio (known as "custom keywords") whose job is to map the rows of a Data File, to models for testing. (Say goodbye to hardcoded column indices and ...
user avatar
-2 votes
1 answer
128 views

Having multiple classes that share the same instance variables for context consistency

I am wondering if it is an acceptable approach to pass instance variables from one object to an object of another class (saving them as instance variables as well) in order to retain the context that ...
user avatar
  • 67
0 votes
2 answers
155 views

Design for three classes with partially shared logic

I am looking for a suitable design which uses composition to allow three classes to share some logic. The problem I am solving is that I have to read 3 different json configuration files from my ...
user avatar
  • 127
1 vote
3 answers
101 views

Exposing multiple classes from the representive package for one entity

I have a simple app for storing the movies, that exposes REST API. I am using spring-boot. I am using this simple app as an example, however, the question is more about general good practice. I am ...
user avatar
  • 181
4 votes
5 answers
393 views

Single Responsibility Principle, Inheritance

I have the following interface: class IHittable { virtual Intersections intersects(const Ray & ray) = 0 } which will be implemented by various geometric objects(Spheres, Triangles etc). Now ...
user avatar
  • 161
0 votes
0 answers
70 views

DDD Value Objects: when is enough enough? [duplicate]

Where do you like to draw the line for modeling a single value as a Value Object v.s. a primitive? For example if I have an internal order number and a customer order number, would you model them both ...
user avatar
1 vote
2 answers
193 views

Model updating itself in MVC?

My group in school is tasked with creating an application of our own choosing which follows good object oriented design principles. The group has chosen to make a tower defense game with help of ...
user avatar

1
2 3 4 5
33