Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
1answer
15 views

Java convention - Implementing two similar functions for two different objects

I have two classes, let's call them Foo and Bar. They both extend different classes (Foo extends X, Bar extends Y), which have some common ancestor "way up" the inheritance tree, something like this: ...
20
votes
3answers
3k views

Why inherit a class and not add properties?

I found an inheritance tree in our (rather large) code base that goes something like this: public class NamedEntity { public int Id { get; set; } public string Name { get; set; } } public ...
1
vote
3answers
148 views

Intent of Command pattern?

In Elements of Reusable Object Oriented software by Erich Gamma, the intent for Command design pattern says: Encapsulate a request as an object, thereby letting you parameterize clients with ...
0
votes
2answers
40 views

Methods taking parameter of Collection should filter the collection themselves or be passed a filtered collection?

Say I have this reasonable contrived situation: public class Toast { public bool Toasted { get; set; } public int MinutesToHeat { get; set;} } public class Toaster ...
-2
votes
0answers
33 views

Storing references in relational databases to compiled functions/methods

Im trying to come up with a sensible solution to a means to store information about a collection of compiled code functions which exposes tooling for performance data processing. These functions are ...
-3
votes
0answers
56 views

How to tackle empathy based System Design interview questions? [closed]

There a lot of system design interviews which ask design question which requires a component of empathy. For example, design a recipe app for elderly people taking input of what ingredients are ...
3
votes
4answers
318 views

How to avoid excessive downcasting when using inheritance

I'm coding a game and I have a design issue in which I have a superclass which all items in the game inherit from. The game is grid based, and the items can be placed at different parts of the grid. ...
2
votes
3answers
268 views

How correct this little game design without removing its design pattern?

Given is a design of a video game in which a player has several possibilities to adjust his character: Game designers realized it's senseless to be a fire-elemental and water-elemental at the same ...
1
vote
1answer
121 views

Java Class Design

I need to send a json response. I use the jackson library to convert the class to json. I have a core java class to which I need to add some more fields to create my json response. I came with two ...
-2
votes
0answers
41 views

Passing member variable as argument into member function vs. some other alternative [C++ & Python] [duplicate]

In a Python class, say it's called some_class that I have written, it contains a member function some_function(self,u) that takes in some argument u. This class also contains a member variable u. I ...
0
votes
1answer
55 views

Designing a maintainable class hierarchy for representation of ASTs

I need to design an AST-like class hierarchy for the introspection of code (like the Java Element API used during annotation processing). But I'm unsure how to make it maintainable and easy to use. ...
2
votes
1answer
133 views

Is it efficient and a normal practice to have one class with thousands of lines of code? [duplicate]

I am currently in a continuous software product development project on base of legacy Java code. The source code is very complicated, which is good and bad. But I am surprised to see that in the core ...
-2
votes
3answers
164 views

Choosing between the lesser of two evils — bad design?

I have two classes, Bar and Baz. Both subclass the abstract class Foo which has a method doThing(). Bar implements a functional interface Now which contains method doThingNow() whereas Baz implements ...
0
votes
1answer
54 views

How to define a structure to store some generic “Variable” classes for easy access later

I'm running into a design problem. My code is in C# but the concepts could apply to any OO language. I'm designing a framework to run experiments, and these experiments have several variables which ...
1
vote
3answers
113 views

subclass with no logic of abstract class

I have a class named Change which should be abstract and have some basic methods. I have classes Insert, Update and Delete that extends Change. In the case of Insert, Update I just use extend and add ...
-3
votes
0answers
70 views

Is putting related functions into a stateful class just for testability purposes a code smell?

Take the following JavaScript module as an example of a utility class helper file that exposes many related utility functions. This module initializes the state of module and the exported functions ...
1
vote
1answer
49 views

Logging patterns from within library code

I am looking for a design pattern for logging from within library code. Suppose I have a function in a library file that i expect will be used by multiple front-ends (lets assume a CLI and a web): ...
0
votes
2answers
63 views

Singleton's applicability clarification

According to the GOF Design patterns' book, singleton pattern should be used when: there must be exactly one instance of a class, and it must be accessible to clients from a well-known access ...
1
vote
2answers
140 views

Encapsulation and input validation duplication

Consider the following example (very simplified): public class Basket { private readonly List<BasketItem> _items = new List<BasketItem>(); public IReadOnlyCollection<BasketItem&...
2
votes
2answers
85 views

Where to implement method to make a logical copy of an object

I am busy developing code that processes a bunch of objects that represent monthly reports for regions (e.g. one instance per region per month). Let's call them RegionMonthlyReport objects. At the end ...
1
vote
0answers
25 views

avoid passing dbsession object to multiple modules

I have a project which has a service-oriented architecture. for example, anything relates to payment is inside payment module. -dao -config -constatnts -middlewares -modules -payment -user -...
92
votes
9answers
14k views

Why should I use dependency injection?

I am having a hard time looking for resources on why I should use dependency injection. Most of the resources that I see explains that it just passes an instance of an object to another instance of an ...
0
votes
0answers
95 views

Software Architecture with C# and WPF

We have the need to develop an offline desktop application for a measurement equipment. While having quite a bit of experience in C++, We are new to WPF and VS in general. This software will have a ...
2
votes
1answer
162 views

Architecture for messaging library C++

I have a library, which sends and receives a set of binary messages and parses them. So far I’ve used inheritance for my design, i.e. class BaseMsg { // init msg from rx'd binary stream ...
3
votes
1answer
108 views

Java inheritance error handling scenario

I looked multiple places for some advice on how to solve this before asking this question, but I couldn't find something similar to this. So I have the following scenario in Java Spring Integration ...
1
vote
2answers
50 views

Thin Controller: Make a Controller Service wrap other Services?

Say you have a HomepageController that' suppose to show all the blogs, users, gallery, and some members-only info (for logged-in users) Normally, it looks like this: <?php class ...
0
votes
2answers
214 views

OOP design problem with Java

I have part of the system that looks like this: Basically, the client decides which API call to invoke on the server based on the flag that is previously provided. It knows in advance which type of ...
0
votes
1answer
114 views

What does related or dependent mean here?

In Elements of Reusable Object Oriented software by Erich Gamma and friends, the intent for Abstract Factory Pattern says: Provide an interface for creating families of related or dependent objects ...
0
votes
1answer
41 views

Pattern for sequencing steps in a job to run sequentially against external system

I am trying to understand how I can make the code for this easy to understand and debug too. The reason I'm asking is that it feels like the kind of scenario which has probably been tackled before ...
-1
votes
1answer
151 views

What software pattern is one where I simply assemble things, such as create an array of certain type of data?

TL;DR: what do I call a section of code that is used to assemble a Graph object? I have a fairly large section of code that is duplicated in a few areas. I wish to extract it into its own class. ...
2
votes
1answer
143 views

why do the factory method and creator class not always need to be abstract

While going through the book 'Head First design patterns ' on Factory Method Pattern chapter , I came across the following question and answer at pp.135 (print publication date of the book : 2004/10/...
0
votes
1answer
153 views

Should the function that operates on the object return it?

Should the function that operates on the object return it? Shortened example: class Example1 { public function method($a, $b) { $result = new Result($a, $b); $this->...
0
votes
3answers
226 views

Calculating the total price of items in a shopping cart

I am making a shopping cart. A shopping cart will have a total amount of money you've got to pay for the products you've selected. I'd like to approach the problem using both OOP (encapsulating it) ...
2
votes
2answers
127 views

The main reason for using the command design pattern for game AI

I've been going through all the design patterns in context of game programming form this book, before starting my next big project. Apart from that I've been reading about them in more general context....
7
votes
5answers
331 views

Information Hiding v.s. Static Type Safety

I'm working on a project with others and we have a discussion about information hiding and static type safety. Our scenario is described below. Language: C++11 Scenario: We want to create a tree-...
-1
votes
1answer
96 views

How to model either relationship?

I am working on a project where a user can send email to either a contact from his directory (Internal) or type an email address explicitly (External Contact) or a mix of both. We also show the read ...
0
votes
2answers
94 views

In which layer should a microservice should send a message to another microservice

In our monolith application, the piece of code that used to handle sending SMSes and emails was written in our business layer. Now the responsibility of sending emails and SMSes is handled by a ...
0
votes
2answers
97 views

Design issue with delegation, inheritance and dependency injection

My question relates to usage of delegation together with inheritance and dependency injection. I have a MailerService class that requires a delegate in order to do its job. Furthermore, I have a ...
3
votes
2answers
113 views

Clarification about an example of the polymorphic open/closed principle

My question is regarding the polymorphic Open-Closed Principle. Say I have the following client: public class Client { private Server server; public Client(Server server) { this....
2
votes
3answers
237 views

Why is the Command desing pattern useful for game AI?

I'm trying to learn the Command design pattern and apply it to the game I'm working on. First I read about the general implementation, and I feel like I understand it pretty well. Now I want to know ...
4
votes
1answer
351 views

Why do we imlpement the Command design pattern like this?

I trying to learn the Command design pattern, I already know how it works and where it is used, but I'm a little bit confused about the implementation. So I know we need to set the context by ...
1
vote
0answers
55 views

How to represent a set of ephemerides?

I am writing software that deals with ephemerides—tables describing the positions and orientations of celestial bodies or spacecraft—and I am struggling with how to represent them in the ...
0
votes
1answer
111 views

Orchestrating Object Instantiation and Intercommunication

We have a C++ project managed by UML software, which generates code for instantiating and passing data between objects. Unfortunately, this software adds a lot of overhead to our builds and ...
1
vote
0answers
72 views

Expected behavior from client when thinking about design patterns?

I'm confused about the behavior I should expect from a client when thinking about design patterns. To be more precise, I'm reading the Head First Design Patterns book, and on the difference between ...
1
vote
2answers
224 views

Liskov Substitution Principle

I am trying to wrap my mind around a Liskov Substitution Principle and I came across this article. SOLID Class Design: The Liskov Substitution Principle In this article, the author gives an example ...
1
vote
2answers
196 views

How to interpret Dependency Inversion Principle

I am working on trying to understand the SOLID object oriented design principles. I was able to get the "SOL" pretty easily, though "L" required some hand holding because I am bad at definitions. I ...
2
votes
0answers
107 views

Is this an example of cyclic dependency?

I'm an undergraduate student and I have this assignment on a Discrete Event simulator. Currently I have completed to the end of v1.2 here. Attached also, is an algorithmic overview. I have wrote my ...
1
vote
1answer
94 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 ...
3
votes
2answers
106 views

How do entities, DTO, DOA work together and what’s their role within a system?

Most of my work is written in Java using Spring Boot. In a recent project my entities contained no business logic, Spring Data was used to handle repositories and I have service classes that ...
0
votes
2answers
273 views

What's the difference between Observer pattern and listeners?

I have used some kind of "listeners" where I have an interface implemented by classes that need to be notified of some event (e.g.: CurrencyListener, with a method currencyUpdated(Currency currency)) ...