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.
1,693
questions
1
vote
1
answer
98
views
Can DI without the dependency inversion be replaced by protected properties?
Many people come from frameworks that implement Dependency Injection and IoC containers for everything (in my case Angular 2+), so, this group of people will try to use dependency injection and IoC ...
3
votes
3
answers
193
views
How do you handle instantiating a large number of interconnected component objects?
I'm currently refactoring our instance startup code, which is currently a 2,000 line mud method. The issue is that that method needs to create a large number (>50) of components/service objects, ...
1
vote
0
answers
104
views
Refactoring code for template class
I have a template class in c++ that depends on a few nontype template parameters. The implementation of some methods, and some field member, depend on the value of the template parameters, in a ...
3
votes
4
answers
284
views
Is a preferences editing GUI a good use case of a object deep copy?
A conceptual question... I have a XML configuration file used to set various behaviours in an application (colours, supressing help prompts etc). On starting the application, the XML is deserialized ...
1
vote
2
answers
80
views
Which association should be in the class diagram
there are a vehicle class and customer class . In short, in the customer class there is a function that shows 'can this person or company rent that car'.The function uses a object of vehicle and ...
0
votes
0
answers
101
views
better structure of a software project to prevent circular dependencies
I am contacting you today regarding a recent problem with circular dependencies. It's about a Spring boot application that accepts data via a Rest API and then forwards it to an internal Spring ...
0
votes
0
answers
50
views
Is using @Transactional together with @Test annotation on the same test method a good practice?
In my current Java project, there is such style of integration test:
@Test
@Transactional
public void testBusinessTransaction() throws Exception {
//...complicate set up code and execution code
...
1
vote
1
answer
49
views
Should I combine use cases related to viewing?
When I did a small project in school about writing a document for Online Auction System in OOAD (Object-oriented analysis and design) courses, I had trouble with multiple Auction viewing use cases ...
22
votes
10
answers
8k
views
Shouldn't deep copy be the default, not shallow copy?
If you have an OO language, where every object always has a copy method, shouldn't that be deep copy by default?
In most languages I know, such a copy method is shallow, since a shallow copy is more ...
0
votes
1
answer
138
views
Class Hierarchy for Generic Parameter Optimization Problems
I am working on a code library containing data structures and algorithms for solving parameter optimization problems. A parameter optimization problem is a problem of the form: given a vector of ...
0
votes
0
answers
54
views
Should I separate algorithms that rely on a data structure into different classes
I'm learning about graph algorithms, so to learn them better I'm beginning to write some of them using c++. For example, I created the code for implementing the Depth First Search algorithm. Here's ...
0
votes
1
answer
27
views
Multiple objects using the same connection for communication, filter messages "above" or inside the objects?
I have a single connection being used by multiple devices, and I'd like to filter the messages so that each device only reacts to messages intended for it. This can be done with an unique ID field in ...
0
votes
2
answers
88
views
How to structure a cart with cart products object
I am new to DDD and I am having trouble structuring an object. I have a cart, where I can add products to it. Each product has some properties like image, title, price, etc. Whenever a product is ...
0
votes
1
answer
74
views
REST - Adding a new field
I have an object with fields like ID, CODE, NAME, etc., and it has its own database table with each field. And I am working on implementing the REST API for this object. I want to expose all these ...
68
votes
8
answers
14k
views
When to *not* use SOLID principles
Coming from a math background, counterexamples are equally, if not more, helpful to me for understanding concepts than examples. I've seen many, many examples of when and how to use the SOLID ...
1
vote
6
answers
347
views
How encapsulating what varies can help us?
I have a question about encapsulation and I read these two topic (this & this) but I got more confused.
I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to ...
0
votes
0
answers
52
views
How to handle multiple-state domain object?
Let's take an example of Order.
An order can have the state new, canceled, shipped, or processing.
The new order can be processed.
The new order can be canceled.
The processing order can be shipped.
...
0
votes
2
answers
113
views
Best way of creating different instance types(facotry method) with business logic?
Say I am trying instantiate an instance of a Table. Table here denotes a restaurant table used for eating. Say I have 3 different table types
enum TableTypes {
SMALL,
MED,
LARGE
}
I have ...
2
votes
3
answers
169
views
Class design using Open and Close Methods
As the title says, Im thinking if it's a good practise to have classes that have Open and Close methods in the sense that they can be reused without a new instance being created again.
Also, if I want ...
2
votes
1
answer
245
views
Domain models: Can they be an abstract class
When talking about having a rich domain model successfully, in real applications, it needs to, somehow, access some abstraction of complex functionality (instead of being a row state calculator the ...
0
votes
1
answer
294
views
Some approach or Design Pattern to implement same method different parameters of Interface class
I am using the Flyweight pattern to cache and reuse objects of the different classes. For example, I have a Shape interface class and multiple types of Shapes implementing the methods from the ...
-2
votes
3
answers
124
views
What are the pros and cons of different combinations of objects and arrays for data storing?
From the article JavaScript 2D Array – Two Dimensional Arrays in JS, I see one way to store data is to put all properties of each element into one array:
let dataRepresentation1 = [
['John Doe', ...
1
vote
2
answers
179
views
Is there a name for this pattern of sealing base classes to a strict set?
In C#, it's possible to create a strictly sealed set of classes that inherit from a base that cannot be further extended like so:
public abstract record MyBase
{
public sealed record A: MyBase;
...
-1
votes
1
answer
163
views
Help in understanding if my design getting complicated [closed]
I have 3 classes
class Backup
end
class Database
end
Class App
end
The backup database has a reference to Database and App, like
class Backup
def getDatabase
Database.create
end
def ...
2
votes
3
answers
346
views
Is having many build-once factories a sign of bad dependency injection design?
I have a form. It contains things like grids. Users do things with these grids and what they do with them is sent to a SQL server. Clearly, the server is a volatile dependency and should be dependency ...
-1
votes
2
answers
79
views
Is there any guideline on how to choose the objects to be modelled? [closed]
From my conversation with @Steve in the question Is there any philosophical theory behind the concept of object in computer science? on Philosophy Stack Exchange:
Steve: More often than not, ...
2
votes
2
answers
230
views
Data getter inside Model or ViewModel in MVVM
I'm working on an app I created for myself using the MVVM architecture. On my ViewModel I have a list_items that, when changed, updates the corresponding UI element on the View. The list of items ...
-1
votes
1
answer
170
views
Using a shared enum across 15 nanoservices [closed]
Originally posted here, moved to code review, redirected from code review back here as there is no code to review. I think the question is enough abstract to be asked here.
I have a mono repo with ...
0
votes
0
answers
105
views
How to handle dependency injection in a library to avoid frequent breaking changes?
Let's say I have a C# .NET library with the following classes:
public class FooService
{
private readonly IDependencyA a;
public FooService(IDependencyA a)
{
this.a = a;
}
...
2
votes
3
answers
221
views
Correctness of an implementation beyond the methods signature contract of an interface
Is there a programming principle/guideline that tackles the correctness of a implementation beyond the methods signature contract of an interface?
Let's say we have a repository interface with two ...
0
votes
2
answers
224
views
How to refactor this tightly-coupled method and (mostly) preserve its encapsulation?
I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax):
void MyObject::twice_bind_cycle() {
_bind1()...
0
votes
4
answers
278
views
Object matching using generic method? [closed]
I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions.
So the first method is as below where I check whether the profile ...
2
votes
4
answers
816
views
Dependency injection using method injection vs constructor injection
Where should I inject the dependency when I write a class? Should it be given to __init__ or to the specific method that uses the dependent object?
Take the below two pieces of code for example, to me ...
-1
votes
1
answer
74
views
Optimal OOP security for PubSub - Should mutual consent be required?
I am implementing the Publish-Subscribe pattern.
I have class Broker and interfaces IPublisher, ISubscriber.
interface IPublisher {
broker: Broker;
publish(channel: Channel, data: object): ...
1
vote
1
answer
71
views
Querying objects in a list by class type vs string identifier - Best practices
I have a class Character who has a list of Spell objects that he can cast.
abstract class Spell {
name: string
manaCost: number
abstract cast() { ... }
}
class InvisibilitySpell extends ...
1
vote
0
answers
173
views
Should I extract my functions/types to new files in TypeScript?
Basically I have this class file which was getting quite large with functions and type definitions.
Is it best practice to keep all the code that works on the same aspect in the same file for "...
-1
votes
1
answer
211
views
Avoid use of the visitor pattern in this very common scenario
Let's assume we need to send a message, and to do so we would like our client to be concerned only with constructing the message (DTO) and using a facade service to send it.
We already know that we ...
3
votes
2
answers
226
views
Efficient way to Decouple classes in class design
I am working on a class design question - design a simple grocery store with a self-checkout system
I am a beginner
After briefly jotting down requirements, I started with the Product class as follows ...
3
votes
2
answers
286
views
Creating an abstraction just for exception handling - a pattern or anti-pattern?
Assume that an external library or framework not under our control exposes a Controller API:
abstract class Controller {
abstract fun call(): Result
}
Assume that we want to handle exceptions ...
-1
votes
1
answer
94
views
How can I prevent an object from being re-sanitized everytime it is passed as input to a function?
Suppose that I have a class named CharStream
Additionally, there are a large number of functions which convert their function input into a CharStream
def funky_the_function(_input):
input = ...
1
vote
1
answer
197
views
Newbie: OOP working with different class-datatypes and loop through them
I'm relatively new to OOP. Let's say I have three different objects/classes defined, like:
Public Class Part
Private m_Name As String = ""
Public Property Name() As String
...
2
votes
2
answers
149
views
Pattern for a base class to do pre-validation and/or post-processing on a deriving class's overridden method?
I have the following pattern repeating itself in multiple places:
abstract class Database {
void connect() {
this.setStatus( CONNECTING )
try {
await this.realConnect()
}
catch ...
0
votes
1
answer
118
views
Is it OK to stick with object graph in React State and should I make helpers for handling it?
I am trying to build ERP application using React frontend and I have not found decisive answer whether to use object graphs in React state?
E.g. I would like to build Invoice view and I have the ...
1
vote
1
answer
114
views
Wrapper class for min/max clamping and validation
I have a lot of classes that have numeric values that are configurable by the customer during runtime and should be clamped between a min and a maximum value. The value changes should also be logged. ...
-1
votes
3
answers
265
views
Is it better to override methods in classes or make methods general?
I am creating the backend of a microservice that will serve as a tool to see in real time how the company's employees are distributed by projects and what days they have assigned to each one. The ...
2
votes
3
answers
127
views
Where to specify UI views in a hierarchy of model objects?
In a Flutter app I'm developing, I have a class hierarchy of model objects of a certain base class. To take a typical example, the abstract base class could be Vehicle. Then I have a (pretty much) ...
1
vote
2
answers
130
views
Designing Products with multiple variations
I have a Product entity:
public class Product
{
public int Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
[ForeignKey("Brand"...
0
votes
1
answer
59
views
Separating model and applicative user in app
I am working on a mobile application, and I want to plan a separation between the model layer that represents a user (that comes from the server) and the "applicative" user that has the same ...
1
vote
2
answers
95
views
Sharing a data class in a flow
Suppose there is a flow of functions in C++
step1();
step2();
step3();
step4();
step5();
and they interact by adding and modifying data on a data class D (only data, no functions). For example, step1(...
0
votes
2
answers
172
views
Is there a UML symbol representing instantiation? This one doesn't seem to be one
The following figure comes from https://spring.io/guides/topicals/spring-security-architecture
I refer to it as a "figure" rather than a "diagram" as I'm not sure if it is.
the ...