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
-2
votes
1answer
72 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(...
-3
votes
0answers
23 views

. What is the structural implication of a system when N(number of class associations) → infinate and | S | ( instances of the class)= constant? [closed]

I have already gone through this answer but I am not able to get it. Full question: What is the structural implication of a set of classes when N → ∞ and | S | = constant and what about opposite ...
3
votes
1answer
63 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 ...
-2
votes
3answers
72 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 ...
0
votes
0answers
33 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 - ...
0
votes
1answer
71 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 ...
0
votes
1answer
58 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 ...
2
votes
2answers
209 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, ...
1
vote
2answers
130 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 ...
0
votes
2answers
145 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 ...
3
votes
4answers
335 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 = ...; ...
2
votes
3answers
199 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 { ...
0
votes
0answers
56 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'...
1
vote
1answer
173 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 ...
-2
votes
1answer
70 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 ...
0
votes
2answers
124 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 ...
1
vote
3answers
88 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 ...
3
votes
4answers
266 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 ...
0
votes
0answers
65 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 ...
1
vote
2answers
125 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 ...
0
votes
1answer
54 views

Design class with different dependency requirements based on configuration

I’m struggling a bit to design the following class: It’s a service class with multiple methods. It depends on a http client interface which must be created in the factory method and can’t be passed ...
16
votes
5answers
4k views

Why are C++ "complex" functions not member functions?

I was looking at the C++ library <complex>, and noticed that functions such as std::conj and std::norm are free functions i.e. static functions not placed inside the std::complex class. Why is ...
0
votes
4answers
141 views

Is casting between interfaces the best approach for capability discovery when using interface inheritance?

It’s frequently taught that downcasting is bad practice. I have a case where it seems necessary, but I’m wondering if there is an alternative way to design this. Suppose interfaces are kept small ...
2
votes
3answers
221 views

Definition of static property of object in OOP

Grady Booch in Object-Oriented Analysis and Design with Applications says: The state of an object encompasses all of the (usually static) properties of the object plus the current (usually dynamic) ...
2
votes
2answers
173 views

What are some alternatives to translate data models in C#?

I have a need to translate data from provider A to provider B. The data is typically pretty consistent, but, often has minor differences; for example: public sealed class ProviderOneFoo { public ...
1
vote
1answer
107 views

How do I ensure that only service models are used as properties?

I work on a system that utilizes a form of n-tier architecture in that we have data and service models. The service models derive from the data models: public class FooDataModel { public int ...
0
votes
2answers
191 views

Is it bad to use checked exceptions as API response?

Consider the following code: public class User { private String password; public void changePassword( String oldPassword, String newPassword) throws ...
0
votes
1answer
111 views

Appointments using time slots

I would like to create a dynamic appointment system between teacher and student to easily allow them to make an appointment. In this system, teachers select their 30 minutes time slot availabilities ...
22
votes
11answers
4k views

In a fluent interface with "with", is cloning expected?

In an object oriented language like Java or PHP (other perspectives welcome as well) if I use a fluent interface like this: my_pizza = (new Pizza).withTopping("pineapple"); another_pizza = ...
1
vote
2answers
359 views

Are experienced developers and software architects able to describe an entire software application in terms of design patterns?

Do experienced developers and software architects see entire application in terms of design patterns? In other words experienced developers and software architects able to describe an entire software ...
0
votes
3answers
182 views

Should validation logic be inside a factory method or inside the object's constructor?

Say I have a hypothetical factory method whose single responsibility is to create MyObjects. However, MyObject should only ever be constructed with an ordered list. Further, MyObjects without an ...
1
vote
1answer
64 views

How to represent association classes in a UML component diagram?

Please consider a class diagram and a component diagram as shown below. In the class diagram I use association classes to represent the relationship between two classes (BaseLink and ShoulderLink) as ...
1
vote
3answers
139 views

Array of a class or class with multiple property arrays

I have a simple question, why would I use an array of a single class over a class with multiple property arrays? Context: I have a series of calculators that extend off a base calculator. Each ...
0
votes
1answer
92 views

How can I allow sub-services to use concrete types, without having an ever-growing type argument list on the primary service?

NOTE: I believe I have a bit of an X/Y problem here, so please, bare with me. Also, I have trouble explaining things sometimes, so feel free to ask me to elaborate, and I will improve anything I can ...
1
vote
1answer
715 views

Low-level Design of a Bike Rental Service

I'm working on the low-level design of a bike rental service and I was wondering if the solution is good or where it can be improved. Context & Requirements I used an exercise I found online which ...
0
votes
0answers
32 views

Architecture with a login

I am on my first big solo task and I am required to create an application that allows companies to work with permits, fill them out, get them signed etc. This web-app is with invite only i.e. it is ...
-1
votes
1answer
79 views

Using OOP objects mapping to DOM elements vs. querying the DOM repeatedly?

I'm trying to make better use of OOP, but I don't have good instincts for this yet and I sometimes worry I'm making things more complicated and/or less efficient. I'm wondering what is the best way to ...
3
votes
3answers
209 views

Is there any performance hit associated by the definition of a static constructor or due to availability of it?

This question is mostly related to the way language implementer do implements static class initalization (pretty specialized question). It is for curiosity and also to potentially improve my code to ...
1
vote
1answer
117 views

How do I "code to an interface, not an implementation" with third party objects?

I have an interface public interface MovieDataFetcher { List<Movie> fetchAll(String query); } And these concrete classes public class ImdbDataFetcher implements MovieDataFetcher { ...
-2
votes
1answer
67 views

How to model a small database application using CRC

I am going through this OO design course: https://www.coursera.org/learn/object-oriented-design/home/welcome and starting to look at the use of CRC cards. (class responsibility collaborators). I ...
-1
votes
3answers
102 views

How do I give a base class a property or method that returns different types in the concrete class?

I have a base class called FieldBase and I want to inherit from it to have different types like TextField and NumberField. I have a property Called Value which for the TextField is String and for the ...
2
votes
2answers
137 views

Factory pattern where some classes require additional paremeter(s)?

We have multiple publishers, that publish the data somewhere. For example, we have ElasticSearch publisher, AWS S3 publisher, or file publisher. Now the interface looks like this interface Publisher&...
0
votes
3answers
120 views

What approach is commonly used when a generic object needs to be converted into a specialized object?

Let's say I have an instance of a superclass and at a later stage this object needs to be converted into a subclass instance (based on additional information that are stored in the object). Is it ...
5
votes
2answers
150 views

Finding the right abstraction and minimising invalid states

I am writing a library to allow two people to play chess for a toy project. For what is worth, it is in C++. I have deemed useful to have a class named Move, which represents a move which needs to be ...
0
votes
1answer
112 views

Should i overwrap functions to maintain Single Responsibility for code organisation? [duplicate]

I am trying to maintain proper code organisation for my codebase. I came across a situation whereby organising my code into class A, B, C is unnecessary as class C can be incorporated into class A and ...
0
votes
0answers
37 views

Which Design pattern (C#) should I use for binding / mapping unrelated models and data contracts and for service using them? Code sample below

New Design: We are porting Legacy code to C#. We have Request and Response Data Contract for each set of Business Data. These are POCO generated using Schema of External vendor. We will be creating ...
6
votes
1answer
171 views

Should operations on properties of list objects be encapsulated in a domain class that wraps the list?

I have a list of product price objects, List<ProductPrice>. @Value public class ProductPrice { Long id; LocalDate startDate; LocalDate endDate; BigDecimal value; } From ...
3
votes
4answers
250 views

Do I have LocalDTOs? If yes, what is a good approach to keep encapsulation of the domain model?

LocalDTO term refers to Fowler's article. Say I have a domain entity Person: public class Person { private String id; private String name; private int age; } This entity has its own ...
1
vote
2answers
98 views

Anemic Domain Model VS coupling and dependencies- design conflict - need an Object oriented advice

on design stage , after finding my main objects , I am always find my self writing "manager" or "controllers" classes in order to handle the connection between them. some of the ...
3
votes
3answers
271 views

Undo/Redo with Command Pattern and Object Destruction

I'm developing a Command Pattern with Undo/Redo support. The environment is Unity C# but should be mostly language-agnostic. My initial commands comprise of adding and removing objects to and from a ...

1
2 3 4 5
32