Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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
vote
4answers
161 views

Object Oriented Design: Repositories and Inheritance

I have an OO design concern. Let's say my models as following: class Account {} class LocalAccount extends Account {} class SocialAccount extends Account {} These Account entities are persisted and ...
104
votes
17answers
18k views

How do you justify more code being written by following clean code practices?

Moderator note This question has already had seventeen answers posted to it. Before you post a new answer, please read the existing answers and make sure your viewpoint isn't already adequately ...
1
vote
1answer
135 views

User class: How do I handle different user “subjects” and still keep my single responsability principal?

I have a User class, this class handles things like: login (UserAuthenticateModel) Handle user sessions: user login tokens, fetching user from session if set in session, ect' (UserSessionsModel) ...
2
votes
1answer
107 views

How to model workflows

I'm building a helpdesk-type system, where there are: Customer - can submit/resubmit tickets; Manager - can review submitted tickets, assign to developers (one ticket to multiple developers), review ...
1
vote
3answers
136 views

Should we have one class for each responsibility?

Consider an Eg. of Library Management System, we can have a design where in a student can search for a book based on it's title from the list of books using a function, something like below (in c++) ...
-1
votes
1answer
61 views

How to build a custom intermediate operation pipeline in Java for a series of API calls? [closed]

I am working on a project which provides a list of operations to be done on an entity, and each operation is an API call to the backend. Let's say the entity is a file, and operations are convert, ...
0
votes
0answers
21 views

Move operator for class that has a member with deleted move operator [migrated]

Class X has a deleted operator= X& operator=(X const&) = delete; Class Y looks like this: class Y { private: X variableX; public: Y(int p) { variableX= X(p); } } I'm ...
-2
votes
1answer
117 views

What is the best way of implement a virtual world like a garden? [closed]

I want to develop a virtual garden with a lot of kind of insects like ants, bees, etc... For example, if I want to create an area of 10x10m². I can implement this with ArrayList<ArrayList<...
173
votes
16answers
91k views

Is it wrong to use a boolean parameter to determine behavior?

I have seen a practice from time to time that "feels" wrong, but I can't quite articulate what is wrong about it. Or maybe it's just my prejudice. Here goes: A developer defines a method with a ...
-2
votes
0answers
24 views

Extending a data class consumed in various place because one of the consumers requires a new field [closed]

I have a class A that is the return type of a process (let's call it M.getData()) that is consumed by several procedures through the code base (lets call them P1, P2 and P3). This class A is part of a ...
4
votes
2answers
232 views

Doesn't repository pattern in clean architecture violate Dependency inversion principle?

From what I have read and seen clean architecture assumes that you have some entities which know nothing about persistence though at the same layer as they reside there might be an interface which has ...
4
votes
3answers
2k views

Java Interfaces in Layers pattern

I'm developing a Java software according to the object-oriented Layers architectural pattern. Every layer should be clearly separated from the rest, and provide a well-defined interface to use it's ...
1
vote
4answers
323 views

Is dependency injection always a best practice?

Recently I started working on a rather large monolithic system. The solution has web, app and api parts and in general just a lot of stuff. It relies heavily on dependency injection and I noticed ...
1
vote
4answers
423 views

Declaring unnecessary variables for readability

I know some languages (C comes to mind) its best to declare as few variables as possible. In a language with memory management like C# is it better practice to continue with this philosophy or should ...
3
votes
4answers
207 views

How to get a decoupled design without injecting repositories inside entities

I am facing the following situation: I have to develop a system that has to calculate the price of a car so i need to calculate the prices of all the Pieces that make up the car and then total them. ...
2
votes
2answers
135 views

Strategy pattern and different implementation

I am still learning Design Patterns and I have a situation in my hand. I am developing a simple employee management Python program. An employee can be a Developer, Senior Developer, Lead Developer, ...
0
votes
3answers
84 views

How can I do a step based design form my applicaiton?

I want to create an application that has some optional steps. But I could not decide how to do step plans. It looks like a workflow. I have a Work entity. This work includes specific business steps. ...
0
votes
0answers
24 views

Ranking / Generating score card based on scoresheet details

I am busy with a score keeping app. And would appreciate suggestions/ help. I will try to be brief and hopefully have explained the main gist of the app below The app basically maintains some scores. ...
0
votes
1answer
68 views

Should there not be methods intended to be only called from inside of the package, but from the outside of the class they're defined in?

Note: This is a follow-up to this question on StackOverflow. I have to write a wrapper in Python to an external API, accessible through HTTP. The code is supposed to be publicly available on GitHub. ...
1
vote
2answers
82 views

Transforming one collection of objects into a separate unrelated collection?

Say I have a customer class class Customer(name, age) somewhere in my code, I have a list of customers List[Customers] at some point, I need to transform this list of customers into a Map with ...
3
votes
1answer
184 views

Understanding interface injection

Quoting the definition of interface injection from Wikipedia : The advantage of interface injection is that dependencies can be completely ignorant of their clients yet can still receive a ...
5
votes
5answers
298 views

Immutable vs mutable mobile object

I need to model a very simple mobile object (Robot) on a rectangular grid. Its state is described by position (basically a pair of integers) and direction (e.g., N, E, S, W). It only has two methods (...
2
votes
3answers
307 views

Confusion on Single Responsibility Principle (SRP) with modem example?

I am currently reading through Robert Martins book "Agile Software Development" book and I am struggling to see how his modem example provides any benefit. He says that he has an interface that ...
0
votes
2answers
91 views

How to design an API wrapper with bulky operations on domain object? (Need guidance)

I need some guidance in designing an API wrapper for my backend APIs. I have tried to keep it as specific as possible. Context: We have a project which supports certain file operations like edit, ...
3
votes
2answers
95 views

How to create a tree-hierarchical structure with unique behavior for every type combination?

Assume: There is some module whose interface is IA. There is some module B, that takes in a parameter an instance of IA, and whose behavior depends upon the type of that IA, meaning (pseudo code, no ...
0
votes
1answer
69 views

How to decide which of two “linked” objects should be contained in the other?

Are there any guiding principles of OO design to take into account when deciding which of two interacting and linked objects should be included as a component into the other (or referenced from it)? ...
3
votes
1answer
247 views

How to handle a software design project when I am the only member of the team with any design experience

Some background I am the newest member of a small team of 3 developers. For the past two years I have been working with them on an application the two of them made roughly 5-6 years ago. This ...
0
votes
1answer
87 views

Structuring methods in classes [closed]

When implementing a class (in any language), I usually try to pack any associated code in small methods, may they be used only once or multiple times. Finally, I end up with a class consisting of a ...
0
votes
1answer
53 views

Defining object definition scope based on domain

I had an architecture question about how to manage objects with different properties based on the services they are in. Is it okay to have an object defined in to different places with similar ...
62
votes
12answers
9k views

Having a flag to indicate if we should throw errors

I recently started working at a place with some much older developers (around 50+ years old). They have worked on critical applications dealing with aviation where the system could not go down. As a ...
0
votes
1answer
91 views

Calling same method on different instance (Polymorphism)

I have situation that 3 different instances with the same method signature are doing their job repeatedly. interface IArgs{ //args stuff } interface IExample{ void Populate(IArgs); } class ...
0
votes
0answers
112 views

Decorator Pattern Java

This is an object-oriented design question that is specific to Spring Boot. I'm extending a Spring Boot application that has an interface that is being extended and used inside another service. The ...
0
votes
0answers
45 views

How would design a wrapper for a large, multi-response api like the one described below?

Let me explain. Lets say there exist some service at some organization that exposes information on a company's assets, from employees company-issued devices(laptops and issues) to the the large xerox ...
0
votes
2answers
153 views

ValueObject - too wordy?

So, I'm having some value objects in my domain, and when I'm using them in one of my builders it looks like this: .withSomething(Id.of(123), Specifiers.of(MySpecifier.of("233"), MySpecifier.of("23423"...
0
votes
0answers
81 views

Job Scheduling Software

I am designing a Job scheduling software. Users of the software will define the job definition in XML like format https://github.com/etingof/apacheconfig/: e.g. <job> job_name myjob &...
8
votes
4answers
728 views

What is “premature abstraction”?

I've heard the phrase being thrown arround and to me the arguments sound completely insane (sorry if I'm strawmaning here, Its not my intention), generally it goes something along the lines of: You ...
6
votes
4answers
420 views

Replacing Linq Methods with Extension Methods

So, I've fallen into the fad trap, and started replacing a large amount of linq queries with extension methods. For example: orders.Where(o => o.Status == ShippedStatus.Shipped).Select(o => o....
2
votes
1answer
272 views

Does it violate GRASP if a Character class checks if it can carry a weapon?

Before I ask my question, I'm aware of Eric Lippert's Wizard and Warrior series. I'm trying to understand GRASP, but I'm having a hard time determining if this class violates GRASP. Suppose if I ...
0
votes
1answer
102 views

Factory Design Pattern Implementation with multiple interfaces and base class

I know it is lot of code. But I am trying to understand the concept of Factory pattern with interfaces and base class. I have a base class of Car that implements an interface which will be implemented ...
2
votes
1answer
112 views

Design pattern for an indeterminate number and format of questions

In my application, I have a finite number of question types, but the order in which they're asked and whether they're asked at all is not known up-front. An example analogy is a hotel booking process,...
0
votes
2answers
75 views

Designing a modular CLI tool

I am building a CLI tool which will potentially support many commands. Ideally, I want to abstract out each command to implement an interface that demands a "run" method. From there on, it would be a ...
0
votes
3answers
201 views

What would be the downsides of creating a derived interface of interface?

Would there be any downsides of creating sub-interfaces for virtual member functions that have different parameter types? A drawing of this is shown in the image attached. Apple and Orange do not ...
1
vote
4answers
109 views

Migration from Anemic Models to Rich Models

I am looking into improving my overall application architecture and (I think) I understand the issues my Anemic Models are causing. Here is my current architecture: Controller with injected Service ...
2
votes
2answers
112 views

Best way to provide configuration parameters for objects far away from the starting point

We are developing complex application on the top of the ROS framework in C++ and recently ran into discussion how to provide parameters to the parts of code far away from the starting main(). The ...
2
votes
5answers
261 views

I feel like these constants should be in a different class?

I have a static class called RenderingUtilities that houses several useful methods and constants. Some of these constants are related to the Earth as an object such as the Earth's radius. I believe ...
1
vote
2answers
156 views

Why are classes named “class”? [closed]

Could it also have made sense to call it a "Form", as in the Platonic sense of the ideal form that represents the thing which earthly objects strive to emulate?
1
vote
1answer
65 views

Utils, Service class and Persistence Layer

I have a method in API handler which does API validation, performs business logic and then makes a call to db. Is it a good idea to move the business logic to utility class or service class? IMO the ...
3
votes
2answers
130 views

Design pattern for similar classes that require different implementations

Edited: Update is at the bottom There could be a common or best practice for this scenario, but I am unfamiliar with it. However, it could very easily be a matter of subjective opinion on how one ...
4
votes
1answer
6k views

Are Spring beans declared as static a poor design choice?

The question is pretty straightforward, I'll try to explain why I want some explainations. (All of this is my 1½-year junior Java developer opinion, which may be more than incomplete. Which is why I ...
1
vote
2answers
100 views

Class Divisibility Metric

A few years ago I was using Sonar (before it was SonarQube) to analyze some Java code, and I remember seeing a useful metric that would come in handy again today. However it does not appear to be ...