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
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
401 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
468 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 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
134 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
168 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
104 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
397 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
72 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
202 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
0 votes
1 answer
56 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 ...
user avatar
  • 149
17 votes
5 answers
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 ...
user avatar
0 votes
4 answers
149 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 ...
user avatar
  • 39
2 votes
3 answers
289 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) ...
user avatar
2 votes
2 answers
190 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 ...
user avatar
1 vote
1 answer
115 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 ...
user avatar
0 votes
2 answers
202 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 ...
user avatar
  • 705
0 votes
1 answer
198 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 ...
user avatar
  • 109
22 votes
11 answers
5k 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 = ...
user avatar
  • 577
1 vote
2 answers
370 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 ...
user avatar
0 votes
3 answers
470 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 ...
user avatar
  • 155
1 vote
1 answer
119 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 ...
user avatar
1 vote
3 answers
147 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 ...
user avatar
0 votes
1 answer
151 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 ...
user avatar
1 vote
1 answer
2k 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 ...
user avatar
-1 votes
2 answers
154 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 ...
user avatar
3 votes
3 answers
380 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 ...
user avatar
1 vote
1 answer
121 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 { ...
user avatar
  • 121
-2 votes
1 answer
84 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 ...
user avatar
  • 1,757
-1 votes
3 answers
259 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 ...
user avatar
  • 117
2 votes
2 answers
411 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&...
user avatar
  • 231
0 votes
3 answers
121 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 ...
user avatar
  • 67
5 votes
2 answers
154 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 ...
user avatar
0 votes
1 answer
120 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 ...
user avatar
0 votes
0 answers
44 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 ...
user avatar
6 votes
1 answer
213 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 ...
user avatar
3 votes
4 answers
391 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 ...
user avatar
  • 705
1 vote
2 answers
123 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 ...
user avatar
3 votes
3 answers
489 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 ...
user avatar
-1 votes
2 answers
194 views

Enum and Programming to Interface and best practices

I am learning stuff and have made 2 microservices, Listener and MyApp. Listener is a jms listener (consumer of messages) and MyApp is the app sending messages to queue. I have 2 type of events CREATE ...
user avatar
4 votes
3 answers
296 views

Is there any language where you can re-call the constructor on an instance of a class and any reason why not?

Is there any language or language feature where you can re-call the constructor on an instance of a class and is there any reason why you don't want to do this? For example, //let's say you have this: ...
user avatar
4 votes
7 answers
4k views

How do interactions between objects work?

I am getting confused when objects interact using OOP. Here i'm trying to model the interaction between a vending machine and a coin. The coin is inserted into the vending machine. The interaction is ...
user avatar
32 votes
10 answers
5k views

Does logging inside a class violate the SRP?

I wrote a class that takes a Logger class as one of its arguments: class QueryHandler: def __init__(self, query: Query, logger: Logger) -> None: self.query = query self.logger =...
user avatar
  • 999
0 votes
1 answer
224 views

Best practice to create model objects in Java

I have an existing microservice that talks to a Natural Language Processing (NLP) product and fetches around 50 fields. I need to create domain objects in Java now from these fields. I read about ...
user avatar
1 vote
2 answers
76 views

Should selected person be part of my application layer? (MVP pattern)

Consider the following GUI screen: When user selects a person from PersonListView, EditPersonView should show person's first name and last name and allow the user edit. So, I end up with the ...
user avatar
  • 705
4 votes
7 answers
657 views

When to use a class with a constructor vs using a method returning an object

I've been working in a rather large codebase filled to the brim with small classes such as class Person { public string name; public int age; public int height; } As a mainly front-end ...
user avatar
4 votes
4 answers
136 views

Approach to keep collection of parent entity sorted when child changes?

Assume a Person has a Phone and a Phone has Contacts. Assume in the real world the Contacts of a Phone are sorted by their first name. When I phone.add(Contact c), the phone sorts its contacts. Then ...
user avatar
  • 705
2 votes
2 answers
94 views

Dynamic loading of objects defined during development for a running system

So I have a design/architectural question. I want to develop a pattern in a programming language that is able to allow a app command-line shell to send commands to a running application to create ...
user avatar
  • 179
1 vote
1 answer
90 views

Imposing an object interface in Python

I wanted to implement a method insertCard in Python which interacts with only a specific type of object called a Card. The Card should always have a cardId and may have additional payload or fields ...
user avatar
  • 163

1
2
3 4 5
33