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
votes
1answer
135 views

Is it good practice to create a static class for database tables calculations?

I need to implement some system (using python pandas dataframe in my case) that parses raw data, then adds on calculated data, and then validates that calculated data (boolean output on some columns) ...
2
votes
1answer
72 views

What to do when you want to apply some common functionality to some specific methods?

I am trying to figure out a design pattern to use (if any exists) to a situation where I would be re-doing some functionality across a bunch of classes. Below is a (simplified) overview of the problem ...
0
votes
1answer
72 views

Initiating a class from its static method [closed]

What is the stand on initiating the class from its own static method? Are there any good practices about this? I feel need of initiating a class from its static method while implementing a job ...
-1
votes
1answer
61 views

Designing command and factory pattern with large conditions

I working on a project requiring quite a lot handlers to handle requests. In general, i'm comunicating with a communication card, receiving requests from any source (User Interface, Server it doesn't ...
5
votes
1answer
8k 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 explanations. (All of this is my 1½-year junior Java developer opinion, which may be more than incomplete. Which is why I ...
0
votes
1answer
97 views

Where to store calculated values of an entity

Trying to figure out the best place to store calculated properties related to a base entity class for use through out the application, namely in view models and DTOs. For example, a base entity class ...
0
votes
2answers
130 views

Creation of Object Model Using UML Conventions

I have the problem statement to make an Object Model for. Problem Statement: Every vehicle has an engine and a gearbox. A gearbox is composed of pulleys working according to predefined gear ratios. ...
2
votes
2answers
104 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
111 views

Where would you handle exceptions: controller, service, repository?

I have been having this dilemma from time to time whenever I have to design or start a new project from scratch. I particularly like how Spring framework is organised in terms of classic software ...
1
vote
2answers
167 views

Is circular reference with Typescript array properties bad design?

I understand that having circular dependency can be bad design. However, I have a question regarding a certain class structure. As an example: ocean.ts import {Boat} from './boat'; export class ...
1
vote
1answer
65 views

Let a subclass determine the implementation of its superclass field(s)?

Say I have two classes abstract class A, class B extends A, and I let A has a private field of type List<String> to indicate that every subclass has a field of type List<String>(so I don't ...
0
votes
2answers
54 views

Application Structure and how to structure Business rules

I am building a cli application in php that keeps track of when people within an organisation should get a birthday present. The application takes an input text file containing a list of names and ...
6
votes
6answers
510 views

I need help solving a common architectural problem with multiple concrete classes implementing an interface

I have a common issue I encounter which I've solved with a Factory class in the past but it always felt a little "off". Let's say I have multiple Exporter classes which implement IExporter, which has ...
0
votes
2answers
35 views

Force State changing of an Object only from Holder

Suppose I have a Button class with a color attribute. I also have a Canvas class which stores all Buttons. Every time a color is being changed, some side action must take place (in this example, for ...
0
votes
1answer
43 views

How to associate tree nodes with other objects before they have unique identifiers

I've been thinking about a simple software design problem. Imagine I am writing a web application to edit a tree of objects. Each node of this tree has an ID property that is filled in when the node ...
2
votes
1answer
140 views

Design pattern for an indeterminate number and format of questions [closed]

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
6answers
2k views

How to change the state of a singleton in runtime

Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via public class AppLogger { public static String file = ...
1
vote
1answer
26 views

Most readable way of generic views placement

What are your suggestions on placing many generic views? Let's consider a classic situation where I have many generic views for CRUD for given models. What is the best way to place them in views.py? ...
0
votes
1answer
81 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 ...
1
vote
1answer
80 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 ...
7
votes
5answers
2k views

Pitfalls of Domain Driven Design with Entity Framework

A lot of tutorials on DDD I studied are mostly covering theory. They all have rudimentary code examples (Pluralsight and similar). On the web there are also attempts by a few people to create ...
0
votes
4answers
301 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/...
1
vote
1answer
111 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 ...
0
votes
1answer
90 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 ...
0
votes
1answer
81 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
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; @...
0
votes
2answers
50 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 ...
42
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 ...
-3
votes
5answers
149 views

One Single Table or Two Smaller Tables

We currently have a Users table in the database, this has quite a few columns in it. Around 50% of the columns are barely used in the system (only on one or two pages). We've been discussing amongst ...
0
votes
2answers
78 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
121 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 ...
0
votes
4answers
181 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
87 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
1answer
123 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 ...
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
171 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
56 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 ...
3
votes
4answers
1k views

How to avoid code duplication while extending two umodifiable classes

I already have this core class structure that can not be changed: class A { //some basic fields and methods } class B { //some another basic fields and methods } It is core classes and I'm ...
1
vote
2answers
105 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 ...
2
votes
4answers
130 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
1answer
126 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 ...
1
vote
3answers
242 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
78 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() { ... } @...
4
votes
3answers
358 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 ...
0
votes
3answers
99 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 ...
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....
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. ...
3
votes
6answers
212 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
99 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
122 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 ...