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.

0
votes
4answers
267 views

Is Template design pattern a bad practice due to inheritance?

I have been using Template Design pattern in my code for implementing CRUD procedures for different resources. There are some steps which are same for many resources and some which need some addition/...
0
votes
1answer
88 views

Reset state or create new objects

I am developing a desktop application that will be run at each station at a call center. It listens for an incoming call, and whenever a call arrives, there are about 30 different classes that need ...
1
vote
2answers
75 views

Domain models vs entity models vs Hibernate lazy loading

In a new Java project I plan to use an extra layer above Hibernate entities. So there would be a CustomerEntity and CustomerDomain. The reason for that is that the CustomerDomain can contain extra ...
0
votes
1answer
76 views

What OOP design pattern would work best for an overseeing class connecting related objects enforced at compile-time?

The Problem I would like to create a managing "overseer" class that connects several related object groups together where any particular group is able to be easily swapped for another using C++11 ...
0
votes
0answers
82 views

How should I go about designing my puzzle-solving application? [on hold]

I really need some guidance, as I've been losing sleep over this. I'm a hobbyist programmer caught somewhere in the middle of having read several books on programming, yet I'm completely unable to ...
0
votes
0answers
90 views

OOP - Composition Design Question

I'm currently working on redesigning a legacy survey system that was a simple CRUD application. The application consists of a: Survey which contains multiple Sections Section which contains multiple ...
40
votes
4answers
7k views

Exception propagation: When should I catch exceptions?

MethodA calls an MethodB which in turn calls MethodC. There is NO exception handling in MethodB or MethodC. But there is exception handling in MethodA. In MethodC an exception occurs. Now, that ...
0
votes
2answers
74 views

What to do when a class' method depends on another class' method to pass an array with a certain key?

To cut a long story short, assume I have a Register, a Provider and a Generator class. In my Register, I have the addItem method that allows me to add items to a collection. The Provider's job is to ...
0
votes
1answer
69 views

Appropriate pattern for injector that sets a property and client that ONLY gets a property

Suppose I have a method in client code that expects an interface... void DoWork(IDataManager data) { //use IDataManager interface in the DoWork method } And the IDataManager interface looks like ...
0
votes
4answers
175 views

methods that has only behavior and not manage class state, is that violation of encapsulation

This is a simple scenario in an office with employees and their manager. In this scenario, both managers and employees have a name attribute. Only the manager can change his own name Only the ...
1
vote
2answers
85 views

Looking for feedback on my Object-Oriented class diagram design

I can't find anywhere else where I can show an OO system design and get feedback on it. Could you identify any major issues with my design and how to fix them? The description of the problem is as ...
0
votes
0answers
18 views

Is it usually good practice to declare an association methods in two models despite only using the association on one side?

Let me elaborate. Say I have a model called Credit that is categorized by a Role model. A real life example would be a track from an album. The track will have credits detailing its' contributions: ...
2
votes
3answers
169 views

How to use a child class property in a function written for base class

in C#, suppose I have written this function public void TryToTurnOn( Device d ) { // some common logic // some more common logic } I then have a class that inherit Device that is ...
1
vote
1answer
55 views

Should I place constants related to reading a specific type of file in the FileReader class or in a separate class?

I am writing a class FileFoodReader (in java if that matters) that reads input from a file containing information about foods and their nutritional values. The file has to fulfill some requirements ...
0
votes
0answers
35 views

What layer should resolve pre-existing Hibernate entities?

Imagine an application that consumes an external data stream and creates objects of this type: @Entity public class Event { @OneToOne(cascade = CascadeType.ALL) private EventInfo info; @...
1
vote
2answers
103 views

Object Oriented Approach to Calculations

I need to determine the average miles per hour for a trip and an object containing a list of trips. I'm thinking of two approaches. First approach, have a MphCalculator class that I would inject into ...
1
vote
1answer
120 views

Should an abstract class implement an interface, as opposed to defining its own abstract methods?

I'm defining a class structure for persisting to our cassandra database, and I'm unsure about using a combination of an abstract class and an interface. I have two concrete classes, one for persisting ...
2
votes
4answers
129 views

Make a class depends on its own ports instead of injecting dependency interfaces

I just have an idea about dependency management in Spring IOC environment that seems to be better than the typical approach, but I am not sure because I can't find any references or example out there ...
1
vote
3answers
241 views

Determining response codes from void functions OOP

I am trying to create a Put endpoint using rest. Let's say that under the link /addresses/12345 I am trying to add a new address (if that id doesn't exist) or I'm trying to update it if it does ...
0
votes
2answers
76 views

How to separate responsibilities of a shared entity

Suppose I have game achievement class that stores achievement information like name, popup message, etc. class GoldMedal implements GameAchievement { @Override String getName() { ... } @...
0
votes
2answers
49 views

PHP class inheritance in variable depths across systems

I have a project where I develop a software which consists of a CORE which is in a separate project, developed separately, and a CLIENT which's base is the CORE but adds to the functionality with ...
0
votes
3answers
98 views

Can I make other developers aware that they can define certain functions for extra-functionality even if they're not required?

The language is PHP. I have the certain, in my opinion, code smell, it doesn't feel right: In my controller class that ingests objects of the same type (interface, it's ViewBlockInterface), I check if ...
4
votes
3answers
354 views

What to do when interfaces force me into violating the single-responsibility principle?

(The code I'd have to post is huge, I'll resume to just function names) I'm currently faced with the following issue on my project: I have a "each module from this framework can have a small view ...
1
vote
1answer
92 views

How should I integrate routine history tracking feature with the routine itself

Let's say I am writing code to run a machine similar to a 3D printer and I have a routine like: machine.moveTo(x1, y1); machine.alignByCamera(); machine.heatUp(); machine.extrude(amount1); machine....
3
votes
6answers
204 views

The ID of an object is null at start. Does that make the object state invalid and violate encapsulation?

This question is related to How should an `Employee` class be designed? In the above question, to uniquely identify an employee, each Employee object has an id field as shown below class Employee { ...
0
votes
1answer
74 views

MVC Controller calling UoW (unit of work) directly instead of going through Service Layer

Currently im injecting my Unit of Work inside the controller. I figured out that in most of the designs, controllers calls the service layer and service calls the repository/DAL layer. Most of the ...
3
votes
2answers
101 views

How do I create database records based on rules?

I'm creating an application in which people meet certain criteria to receive a payout at certain milestones. In order to earn these milestones, users will record activity in a log, and when they have ...
2
votes
3answers
226 views

What are possible benefits of using a class instead of a function here?

I often see classes of this form: class Thingy { public Thingy( /* some arguments here */ ) { // Initialize some member variables. // Maybe do some other things that // ...
1
vote
4answers
190 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 ...
2
votes
1answer
119 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
1answer
145 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) ...
105
votes
13answers
19k 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
3answers
142 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++) ...
-2
votes
1answer
121 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<...
4
votes
2answers
304 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 ...
1
vote
4answers
394 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 ...
3
votes
4answers
218 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
146 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
0answers
28 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. ...
1
vote
4answers
458 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 ...
1
vote
2answers
86 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 ...
2
votes
3answers
327 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
1answer
92 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
2answers
121 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
55 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 ...
0
votes
1answer
96 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 ...
1
vote
1answer
81 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. ...
0
votes
0answers
135 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 ...
1
vote
1answer
57 views

How to design a wrapper for a large, multi-response API?

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 printers on ...
0
votes
2answers
154 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"...