Skip to main content

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
6 answers
851 views

Is it ok to assert on the behavior of return values of a testable class?

So I have a dialog for generating a random password. The user can set min, max, character categories (upper, lower, etc.). What the user basically does is configuring a StringGenerator that does the ...
Sergey Zolotarev's user avatar
0 votes
5 answers
275 views

Is it bad to pass builders as constructor arguments?

Note. It's a "spin-off" from my previous question. Not a duplicate — it focuses on a different topic I got to know builders from Bloch's Effective Java. However, I made two changes to his ...
Sergey Zolotarev's user avatar
1 vote
3 answers
366 views

Should everything be buildable?

You have some class that performs a certain job public class MyClass { public MyClass() { // ... } // ... } Then, a spec change comes around. The responsibility of the class is the ...
Sergey Zolotarev's user avatar
2 votes
2 answers
244 views

Is it ok to extend utilities?

Apache Commons has StringUtils. It's great, but I wish it had a shuffle() method or similar Is it ok to create my own StringUtils that extends Apache's StringUtils and adds the method (Apache's class ...
Sergey Zolotarev's user avatar
0 votes
3 answers
125 views

Exposing dependencies results in "fat" constructor. What should you do next?

You take a non-testable class with a lot of static dependencies and expose, and expose until they are all explicitly declared in a constructor But halfway through that nice plan, you notice your ...
Sergey Zolotarev's user avatar
1 vote
2 answers
259 views

OOP Design of a Mathematical Group

A Group is formally defined as a set of Element's, over which a single operator mul is defined. There are different kinds of Groups, and each kind requires a different set of parameters. Operator mul ...
Mahyar's user avatar
  • 11
1 vote
2 answers
178 views

Abstraction for user notification

We have a desktop Swing application. It executes operations against a DB. It could be plain DML, it could be procedures. In both cases, it could result in an error. In that case, we need to display a ...
Sergey Zolotarev's user avatar
1 vote
2 answers
158 views

Passing required args of same type to super constructor

Imagine an abstract superclass with several required (and final) properties of the same type How do you pass the args in its subtype safely? This is not safe since you can confuse the order by mistake ...
Sergey Zolotarev's user avatar
1 vote
1 answer
288 views

Mapping complex objects to other similar complex objects

I am working on two applications that serve the same purpose. The first application is more feature rich and its types are more complex, but uses old technologies and will be retired. It will ...
vicch's user avatar
  • 127
2 votes
2 answers
271 views

Optimal way to share data between different classes

I have a C++ code that performs simulation of a physical system which deals with motion of objects. It has the following classes: Class Main, containing all the main calculation methods and the data ...
grjj3's user avatar
  • 131
2 votes
2 answers
337 views

In unit testing: How to abstract a dependency of subject under test?

Disclaimer: I am learning unit testing. I am also kind of beginner in object-oriented design. Currently, I am involved in the development of an application to manage the finance of a humble food ...
Siva Sankaran's user avatar
2 votes
1 answer
132 views

For N and NBuilder, should N be an instance variable of NBuilder, or all parameters of N be instance variables of NBuilder,finally new N() in build()?

As far as I know about builder pattern, for example, an object, Student: public class Student{ private String name; private int age; //setter and getter } to apply builder pattern to ...
wcminipgasker2023's user avatar
6 votes
4 answers
1k views

How to avoid init methods when 2 objects need the reference of each other?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first ...
wcminipgasker2023's user avatar
3 votes
1 answer
166 views

Seeking Clarification on the Abstract Factory Pattern

I am seeking clarification on the exact purpose and definition of the Abstract Factory pattern. According to the GoF (Gang of Four) book, the intent of the pattern is to: Provide an interface for ...
Codisattva's user avatar
3 votes
1 answer
240 views

Object-oriented programming design with relational database tables

I want to understand what is considered best-practice to better align with OOP when handling relational databases. I cannot find any online examples where classes and a more maintainable/re-usable ...
Yannis's user avatar
  • 147
14 votes
3 answers
5k views

My use case diagram is a mess. What can I do?

I was asked to build a use case diagram for a case study of a charter boat company. I said that the system will implement a shift away from their use of manual forms into an online booking and payment ...
Ivan's user avatar
  • 249
25 votes
15 answers
18k views

How far can you push Object Oriented Programming?

A getter is a failure to design an object. It violates encapsulation which is a core principle of object oriented programing. Now please tell me, how do you design a libraries hash table collection ...
candied_orange's user avatar
0 votes
1 answer
149 views

Is it good practice for object APIs to be required to be called in sequence to gather information?

I had this discussion with someone and it ended ambiguously. Suppose you have a class that needs to Parse a file to gather some information. It can expose this information to you after the fact. ...
user129393192's user avatar
2 votes
2 answers
372 views

Should private attributes or public attributes be the default in Python classes?

In python we use a leading _ to make object attributes implicitly "private". If we want to give people set/get access we can use the @property decorator. Or, if setting/getting is allowed ...
Alexander Soare's user avatar
1 vote
2 answers
124 views

How do I reduce number of FieldValidator derivations?

I am trying to write RSQL Parser which checks if the RSQL is logically correct. while the RSQL Java library checks whether the RSQL expression is grammatically correct, it doesn't check if the ...
Govinda Sakhare's user avatar
19 votes
6 answers
7k views

Is utilizing a singleton for a cache an antipattern?

I'm currently writing an MVC application and I need a class that can: A: get, add and remove data(specifically a TreeSet of sorted strings that I want stored in memory, but I doubt the data itself is ...
Tyler Del Rosario's user avatar
0 votes
1 answer
176 views

Function objects with no state shouldn't be object oriented? [closed]

My question relates to this topic here: Are classes with only a single (public) method a problem? There I read in the comments often something like that: It is no longer object oriented. Because ...
Robin Kreuzer's user avatar
14 votes
5 answers
5k views

How to "Tell, don't ask" when 2 objects involves in the condition and the decision at the same time?

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know the following is bad: if(a.isX){ a.doY(); } public class A{ public boolean isX; public void ...
wcminipgasker2023's user avatar
-3 votes
1 answer
193 views

Should you default to using classes in C++? [duplicate]

I recently discovered the KISS and YAGNI principles which made me question my usage with classes because I use them constantly without really thinking about it and I realized my code could be much ...
Konjointed's user avatar
-3 votes
1 answer
185 views

How should I architect a cricket scoring app?

Cricket scoring is complex and I want to build an app in part to practice good design principles/patterns and develop a clean solution. A few high level classes I have in mind are: Match | Innings | ...
zadane's user avatar
  • 397
0 votes
0 answers
48 views

Setting Dependency Design

Hello I'm currently designing an GUI application who's main job is to update and display settings and some other data. For context, I'm using QT framework. I'm starting to refactor the settings ...
mcmatt90's user avatar
2 votes
2 answers
537 views

Is this architecture overkill? What is a good way to architect this software?

I have an algorithm I am trying to implement that has steps 1 to 5. There are several different ways I could implement each step. Each calculation step is essentially just an astronomy calculation, ...
Hunter's user avatar
  • 187
0 votes
1 answer
145 views

How to model in OOP interactions with entities in other systems?

Assume we are designing a typical bank account management system. Customers can have one or more accounts. Customers can deposit cash, withdraw cash or transfer money to another account (and, of ...
A. Darwin's user avatar
  • 109
0 votes
2 answers
199 views

Possible violation of LSP when adhering to ISP?

Recently I read about ISP and wanted to implement it into my project. While implementing my design I think I found a flaw which violates LSP but I'm not sure. Given I have a game project, in which ...
Boudebouz1's user avatar
0 votes
1 answer
155 views

Shopping Cart Design with SRP: Handling Cart Creation and Update Separately

I'm working on designing a shopping cart system that respects the single responsibility principle. However, I'm facing a challenge when it comes to handling cart creation and updating separately. ...
Thiago Dias's user avatar
0 votes
1 answer
121 views

Functional interfaces or decorator-like implementations [closed]

Consider Chess as an example. Say, we have a lot of domain objects that are alike, in this case chess pieces. I have two proposes to implementing the behaviour of chess pieces. Both uses the following ...
Daniel Birn's user avatar
0 votes
4 answers
178 views

What is the advantage/disadvantage of returning a UnSubscribe class to Observer as opposed to just calling a UnSubscribe method of Observable?

There are two ways to provide a way unsubscribe in Observer Design Pattern. 1. Provide a simple void UnSubscribe method: public void UnSubscribe(IObserver observer){ // remove observer from List of ...
SamuraiJack's user avatar
0 votes
0 answers
95 views

By creating an architecture, it is better to have many classes that handles different scenarios, or a single one that handles all? [duplicate]

During my limited professional experience, I have been involved in microservices projects with a common structure: The Controller takes a request and validates it using the jakarta.validation....
Paul Marcelin Bejan's user avatar
2 votes
5 answers
366 views

Refactoring Java class for a cleaner design

I inherited some code that I have spent some time reviewing to get a better handle on its design. There is one class that I came across that I have an idea for refactoring, but I am wondering if it I ...
user1154644's user avatar
1 vote
1 answer
167 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 ...
Vitor Figueredo Marques's user avatar
4 votes
3 answers
249 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, ...
thecoop's user avatar
  • 539
1 vote
0 answers
124 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 ...
francesco's user avatar
  • 119
3 votes
4 answers
318 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 ...
mountainred's user avatar
2 votes
3 answers
151 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 ...
Tunahan's user avatar
  • 31
0 votes
0 answers
197 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 ...
Phoenix's user avatar
  • 67
0 votes
0 answers
61 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 ...
Rui's user avatar
  • 1,871
1 vote
1 answer
63 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 ...
Đặng Quang Huy's user avatar
24 votes
10 answers
9k 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 ...
Mecki's user avatar
  • 2,360
0 votes
1 answer
143 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 ...
Treker's user avatar
  • 199
0 votes
0 answers
65 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 ...
KetDog's user avatar
  • 101
0 votes
1 answer
34 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 ...
Markus Meskanen's user avatar
0 votes
2 answers
161 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 ...
Bernardo Benini Fantin's user avatar
0 votes
1 answer
145 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 ...
Arpit Jain's user avatar
71 votes
8 answers
17k 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 ...
Derek Allums's user avatar
1 vote
6 answers
427 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 ...
Mehdi's user avatar
  • 29

1
2 3 4 5
35