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
3
votes
4answers
261 views

OOP - Is this data hiding?

I've been reading about data hiding and there seem to be slightly different definitions of it, so when trying to come up with a practical example, I'm not sure if I'm doing the right thing. So far, I ...
1
vote
4answers
122 views

What if there is specific logic for one particular value of an enumeration class?

Background: I have seem some argument for using enumeration classes instead of enum in C#, in particular, this section from a book available at MSDN. On the references there is this "Enums are Evil" ...
0
votes
1answer
127 views

What is a good Object-Oriented design for geometry objects when building libraries dealing with geometry operations?

I am trying to design an object-oriented library to handle geometric calculations. However, I am trying to exaggerate on being "tightly" object-oriented and applying relevant "best practices". I know ...
2
votes
2answers
76 views

Object Instance Diagram - What can be modeled?

According to my professor, one of the following relationships cannot be modeled in an object instance diagram: Association Composition Generalization I made the argument that the association could ...
1
vote
0answers
25 views

How Best To Store Data Structures Around Flow

I'm working on building a simulator for HVAC units. The conceptual model I am working with is basically that an HVAC unit has inputs and outputs, and I need to be able to calculate the outputs for a ...
1
vote
2answers
72 views

Best practice for a group of similar functions

I’ve built a small little library that I think really aids in PHP development. It makes secure by default database transactions, makes cURL requesting anything easy (including files), and it has a ...
-1
votes
3answers
170 views

Is it ok to have a class contain a list of its parent object?

I'm working on a software in which the client wants the admin to have all the rights to view and update the info of other employees. The admin is an employee itself so this is what I've come up with ...
0
votes
1answer
174 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
87 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
78 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
64 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 ...
0
votes
1answer
145 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
173 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
1answer
103 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 ...
6
votes
6answers
539 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
1answer
45 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 ...
0
votes
2answers
42 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 ...
1
vote
1answer
28 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
4answers
308 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
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 ...
2
votes
2answers
121 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
83 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 ...
43
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
81 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
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 ...
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
90 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
173 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
58 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
106 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
141 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
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
3answers
243 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
80 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
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 ...
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 ...
4
votes
3answers
369 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
221 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
109 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
227 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
194 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
122 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 ...
2
votes
1answer
148 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) ...
106
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
145 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++) ...