Questions tagged [class-design]

General guidelines on how to design classes with best known industry practices.

Filter by
Sorted by
Tagged with
2
votes
2answers
50 views

Organization of C++ source code for reusable components

I'm implementing a custom templated container as part of a learning project in C++. The container makes use of different components like serialization, memory management, iterators. I am wondering ...
1
vote
2answers
92 views

How to name two versions of the same object, where one has a smaller amount of data and one is the “complete” object

What is the best way to name two classes that describe the same object, but where one of those classes does not hold the complete information? And should I make one of the classes inherit from the ...
0
votes
3answers
141 views

Should I make the class static or non-static for the following case?

I have a class which has the purpose of providing file operations i.e. providing functionality to create the file, read, write and rewrite to the file. So, the main constituent of the class is ...
3
votes
1answer
52 views

How can I provide a class diagram for a system that contains creation of an object that contains a combination of property?

I am designing a system that contains organizational hierarchy management. There are four roles in the system which are the user, admin, manager and head of procurement: I am trying to let the ...
2
votes
4answers
144 views

Splitting class responsibilities without exposing private data

I'm struggling to find good ways to split up classes without exposing private data. Most articles I read about SRP seem to ignore how the new classes that take on the separated responsibilities access ...
3
votes
4answers
295 views

Do “avoid primitive obsession” and “use most abstract type as possible” contradict each other?

According to Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession"?, I should define "price" like this: public class Main{ private Price price; } ...
-2
votes
0answers
18 views

In Spring Boot, why (or why not) use separate “data” and “form” classes for the same entity?

I'm working on a Spring Boot application which uses a Repository-Service-Controller-View architecture, and am about to implement my first validated web form, namely one to create or modify a user's ...
1
vote
2answers
234 views

Common interface to handle different data type

I have a design question about data. I have a class "T" that has a single interface handling two data types as described below. The class T is constructed to handle one of the two data types. Users of ...
21
votes
4answers
4k views

Constructing an object: should I expose or hide parameters passed to the constructor?

I've a habit I just mechanically do without even thinking too much about it. Whenever a constructor is waiting for some parameters, I consider this a public information that should be available by ...
13
votes
3answers
5k views

How does encapsulation actually work?

I made the following diagram to show a typical separation of concerns as typically taught - Here ClassA indirectly uses ClassB via the ISomeInterface, of course ensuring it doesn't know ClassB exists,...
0
votes
2answers
62 views

Needs to understand the difference between boundary, controller, logical class types

As the title implies I am trying to understand the difference between boundary, controller and logical class types, which are used in the MVC pattern. I will do so using an example. Please consider ...
0
votes
1answer
88 views

Responsibility-driven design

I am quite confused about the responsibility-driven design concept. Mainly because of ever so slightly changing definitions depending on the source. Quoting BlueJ (the book I am learning that ...
1
vote
2answers
88 views

Modeling Class hierarchy that may change during runtime

I've been building an application that processes documents through different filters. I have a class (or better as an interface for creating test-doubles?) called Document. The Document class ...
0
votes
2answers
149 views

Simple Poker Simulation - How to design it well

I trying to create a little poker Texas Holdem simulator .. In my solution have some class : Premise : I know about Fisher Yates algorithm. I will implement it later Keep in mind that the next ...
-1
votes
2answers
96 views

where to put Read/Write threads in c++ classes

I am programming a UART interface (in LINUX) and I want to use a class for that. The way I have it right now is I have a method for write and one for read. The reading is started in a new thread to ...
0
votes
3answers
194 views

Builder Pattern - Must it be part of The same Class?

For complex object creation, I am quite fond of Builder Pattern. My 1st question is "Do I need the Builder to be inside my complex class blueprint, or Could I actually have it outside?" e.g. Are the ...
0
votes
2answers
96 views

Designing a tiling grid

I am implementing a grid-like game. The initial state is shown here: +++===+++===+++===+++===+++===+++ | | | | | | | | | | | | +++===+++===+++===+++===+++===+...
0
votes
0answers
125 views

Designing reusable game/chat server

I'm encountering difficulties with making a reusable design for a game server in C#. Are there better architectural or design patterns that could be used here? If I group similar system functionality,...
1
vote
1answer
83 views

How to add supporting information to the existing java object?

Is there a way or design pattern to add supporting information to the existing java object? Example I have a model class Parent and it has child models. Its nothing but hibernate entities with parent-...
4
votes
1answer
97 views

Hexagonal architecture and translations: how to model it properly?

Imagine a backend service modeled by a hexagonal architecture, where the domain has a class modeling, let us say, a Step of a creative flow that a mobile app will use: class Step( val stepId: ...
2
votes
3answers
153 views

What options are available to replace an `enum` with a multi-type solution?

A Quick Note I know the question title is a little odd but I haven't had much caffeine this morning so I'm having trouble thinking clearly right now. If you have any suggestions for a better title, ...
1
vote
1answer
57 views

Model-view-controller architecture, desktop application and database connection

Let's assume we have a class structure for a particular application (a University manager for example, with classes representing semesters, subjects, timetables and so forth). It is to be a desktop ...
6
votes
4answers
1k views

How to respect Single responsibility principle and use exception handling at the same time?

I am getting confused on how exactly should I be using exception handling inside a class that respects S-Principle. For example consider this code in C#: public class BcryptDecrypt { ...
1
vote
2answers
76 views

Class property re-use vs redundancy

TL;DR - When designing classes for MVC use, is there "best practice" for how classes should be structured to eliminate property duplication and/or redundancy? I'm trying to avoid large (one-size-fits-...
9
votes
5answers
2k views

Too much abstraction making code hard to extend

I'm facing problems with what I feel is too much abstraction in the code base (or at least dealing with it). Most methods in the code base have been abstracted to take in the highest parent A in the ...
1
vote
1answer
67 views

Where should a displayable property be implemented?

I have a class that contains insurance benefits. There are many values, such as coverage level percentages, maximums, deductibles, etc. Most of the time, I only need a handful of display friendly ...
0
votes
2answers
127 views

Make a group of classes visible only by a single class

I have a group of classes (let's say B,C,D,E) that basically represent specific operations a user can execute. I would like to have a single point of access for creating these object and launch their ...
4
votes
2answers
510 views

How to redesign a static class to make it extendable?

I'm working on a console extender project and I'm getting to a point where I feel I need some refactoring. The only public class in the project is called ExConsole, and to make it just as easy to ...
0
votes
2answers
63 views

Module with globals or Class with attributes?

Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so: STATE_VAR = 0 def ...
9
votes
4answers
1k views

Can renaming a method preserve encapsulation?

I was reading this page, about when getters/setters are justified, and the OP gave the following code sample: class Fridge { int cheese; void set_cheese(int _cheese) { cheese = _cheese; } ...
2
votes
3answers
214 views

Object Oriented Design - Genome Class / Mutation Class

Context I am having an argument with my friend on how to start implementing a Genetic Algorithm called NEAT (NeuroEvolution of Augmenting Topologies). Method 1 I am arguing in favor of having two ...
1
vote
1answer
78 views

Using virtual inheritance for an interface system based on abstract classes

I want to use a physics engine (like bullet or PhysX) in my program, however I want to hide the actual physics engine from it, so I can easily swap it out with another during run-time (e.g. switch ...
1
vote
1answer
68 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 ...
1
vote
4answers
277 views

Class diagram for electric guitar and bass

Hi I was recently asked this in an interview to represent a 6 string guitar and a 4 string bass in class structure. I am still new to software design and analysis so was not able to complete the ...
0
votes
4answers
206 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
4answers
136 views

Should supporting algorithms be in their own class?

My Widget class has a method called loadWidget. This method needs to shuffle an array to work properly, among other things. In Widget, I could implement a Fisher-Yates shuffle as its own static method ...
3
votes
6answers
391 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
73 views

Inheritance or composition for a more advanced implementation of a class?

So i have a class called VirtualMouse, it is used to perform mouse actions such as moving and clicking. public class VirtualMouse { public VirtualMouse() { } public void ...
3
votes
1answer
128 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
903 views

Ordered vs sequence in association in UML

I am trying to understand UML class diagrams. Imagine two classes that are related with each other by association. What is the difference between {ordered} and {sequence} for the association?
1
vote
1answer
151 views

Building a MVC Framework: Should I get an instance of Database, or should I extend with a “general” model class that already has an instance of DB

I am trying to get a database instance via any model-class that uses the database. This is ideal in my opinion: class UserAuthenticator { private $db; private $customer; public ...
1
vote
2answers
322 views

What is this anti-pattern's name? (Specialization added directly to a general purpose utility component)

I'll describe the anti-pattern I see occasionally as this. Rather than using encapsulation or inheritance, a utility library grows with feature specializations directly added to it. Subsequent usage ...
1
vote
0answers
311 views

Designing a multithreaded TCP/UDP server for audio sharing

As briefly introduced in the question title, I am trying to design and implement a server application able to let clients share audio contents between themselves. In order to achieve that, I decided ...
1
vote
3answers
162 views

Calling full functionality private functions from public functions

I have been programming my classes in the following mode. I create a public function that has a call to a private function that has all the logic and functionality. Something like: public class ...
2
votes
0answers
77 views

Is assigning a method in the constructor good practice? [closed]

Here's a class with a method that calls different functions based on a parameter set in the constructor: functions = { "arg1": f1, "arg2": f2, "arg3": f3 } class C: def __init__(self,...
0
votes
2answers
102 views

Where should the logic concerning a class's behavior reside? In the class itself or in the calling subroutine?

I have a car object. The car cannot be driven unless it is turned on. When should I check to see if the car is on before I try to drive it? In the main program? class Program { static void Main(...
3
votes
5answers
294 views

I feel like these constants should be in a different class?

I have a static class called RenderingUtilities that houses several useful methods and constants. Some of these constants are related to the Earth as an object such as the Earth's radius. I believe ...
2
votes
1answer
139 views

Should I break functionality out into new classes?

I currently have an object that is composed from several simple objects. Each simple object is used to render a particular portion of the larger object as a whole. Think of it as building a 3D ...
1
vote
2answers
201 views

Why are classes named “class”? [closed]

Could it also have made sense to call it a "Form", as in the Platonic sense of the ideal form that represents the thing which earthly objects strive to emulate?
2
votes
2answers
44 views

Create a new class with minimal data VS. using original class and setting non-necessary data equal to 0 or null?

I am using Scala for my example but I believe this probably could apply anywhere. Say I am using a class somewhere in my project that reads in data from a live stream of events which monitors where a ...

1 2 3 4 5 8