Questions tagged [class-design]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
82 views

Should a class be an attribute for another class if all I need is the data from it?

Title sucks, I know, but I'm having trouble describing my question. Say I have a class Three_Eyed_Robot that sees the world in RGB through three eyes. Lets call them Red_Eye, Green_Eye, Blue_Eye, each ...
user avatar
2 votes
3 answers
115 views

Referencing transient class attributes

I've just started dipping my feet into OOP. Is it considered bad practice to have classes that reference attributes that depend on another function being called and thus may not exist (version 1)? I'...
user avatar
1 vote
2 answers
146 views

C# - Class creating instances of other classes requiring different services

Context I have a service class whose sole purpose is to interact with a specific API, let's say the Automotive API. The API mostly works with generic AutomativeRecord which basically represents a ...
user avatar
1 vote
3 answers
171 views

Class design: should I split responsibilities or should the class take care of itself?

I have a Curve class that has some CurveData inside as private member as well as getter functions for topics of interest (e.g. peaks, width and so). So the math logic of a curve is inside this class. ...
user avatar
0 votes
1 answer
92 views

What information should one infer from a class header that marks its constructor explicit?

If a class is written well, you should be able to gleam all relevant information about the class simply by looking at its header. If one sees that the constructor is marked explicit: What should one ...
user avatar
  • 3,379
0 votes
1 answer
68 views

Dependency Injection for dynamic objects

I am learning about Dependency Injection and I have been recently implementing the following classes for an app that executes commands over ssh using Python. I am confused about whether I am using it ...
user avatar
-1 votes
1 answer
74 views

Calling helper functions in a Python `__init__` function

Problem I am currently working with a class that necessarily has a very complicated initialization function (>350 lines of code) given that many computations and attributes need to be performed and ...
user avatar
0 votes
2 answers
89 views

Should I instantiate the state objects of a finite state machine?

I have a class hierarchy with a base State class, several inheriting classes each named after their relevant state, and an FSM class that contains all the states in a particular state machine as well ...
user avatar
  • 329
0 votes
2 answers
140 views

How to handle continual method addition to an existing class

I find myself often adding more and more methods to a specific class, is this class heading in an unmaintainable direction? Or is this class fine even if it has 50 or more methods? let's call the ...
user avatar
  • 111
0 votes
1 answer
215 views

aliases for namespaces in headers?

Everytime I write a header I end up doing something like this: #ifndef D723E2D5_1943_4166_87CC_73F5C9C47544 #define D723E2D5_1943_4166_87CC_73F5C9C47544 #include "RandomIntegers.hpp" ... #...
user avatar
  • 161
-1 votes
1 answer
74 views

Design: Designing a Status Tracking Tool

We have a robust set of micro-services available. For simplicity, let us call the services S1 S2 S3 S4 S5 For simplicity, think of the flow to be this. S1 -> performs step1 (start step) S2 -> ...
user avatar
0 votes
0 answers
27 views

Modeling a predicate/criteria builder

For a project I am currently doing, I am supposed to build a way to express "rules" about a certain system in a database and then be able to check if entities fulfill this ruleset or not. ...
user avatar
-3 votes
2 answers
151 views

Using templates to define sizes of containers?

Is using templates for specifying capacities of containers a good use or misue of the templates? Eg. template <unsigned int Length> class String { public: String(); String(String& ...
user avatar
3 votes
5 answers
278 views

Add specific behavior inside classes

I'm learning to make games with OOP and there's something I don't understand. What I can see is that the more I add methods to a class, the less it becomes reusable and flexible. For example, if we ...
user avatar
4 votes
2 answers
196 views

Should similar standalone functions go in a class?

I'm working to create a library in python that myself and a few colleagues will use. I'm struggling to conceptually understand how to best organize some code that feels like it doesn't cleanly fit ...
user avatar
  • 79
-1 votes
2 answers
87 views

Is an abstract role needed to ensure that a customer can only have one role out of several? [closed]

I have the following UML class diagram in a C++ context. I want to make sure that a Customer can have only one role: Can the Customer now only assume one role, and what does <<abstract>> ...
user avatar
  • 11
0 votes
1 answer
82 views

C++ class design with shared pointers methods [closed]

I dont exactly know, how to handle the problem, where one class uses shared pointers but I want to call its method from inside other class via this pointer. class Bar { public: Bar() = default; ~...
user avatar
2 votes
3 answers
236 views

OOPS Relationship between Soccer Field and Soccer Player

I am trying to design a simple Soccer game. To keep things simple, I am having a SoccerField to represent the field and a Player class to represent an individual. A SoccerField will contain a list of ...
user avatar
1 vote
3 answers
214 views

What behaviours to put in and out of a class

Let's say I have a class modeling some kind of object, for example a graph (in the graph theory sense). I will have the graph structure and data inside the class, but what about other more complex ...
user avatar
0 votes
0 answers
38 views

Should ad-hoc values live in the component as class members, or not?

Say we have a recipe website with a recipe-list component which loads onto itself cards of individual recipes: <ul class="recipe-list"> <li *ngFor="let recipe of recipes"...
user avatar
  • 177
0 votes
1 answer
101 views

Time consideration in multiplicity of classes

In the following image, regarding a CD shop that rents its music CDs. My question is regarding the correct multiplicity of X. I can think of several possibilities for X: X= 1..1 as each copy of ...
user avatar
1 vote
1 answer
66 views

Videotape copy as an attribute or Class

I am going over tutorials regarding class design; in one, a videotape can have multiple copies and each copy can be borrowed by a borrower. Please see figure A: I am trying to understand why the ...
user avatar
1 vote
0 answers
87 views

How to measure LSP from SOLID Design Principles using NMI, NME and NMO

I do understand the SOLID Principles and LSP, but I want to be able to meausure how well a class diagram obeys to the LSP. Therefor I have found the "Value of LSP" metric, here is a guide ...
user avatar
  • 21
-2 votes
2 answers
191 views

OOP: How to Manipulate Objects Using ORM Techniques?

about those objects and arraylists inside the classes, derived from one-to-many relationships, using the ORM techniques, what's the best way to deal with them at the time of setters and validation ...
user avatar
-2 votes
4 answers
261 views

Is using member variables as bad as using globals?

Is this an acceptable use of member variables: One method sets the variables so that another method can use them. Would it be better to return the value in a list or tuple from func1? If I don't do ...
user avatar
  • 115
1 vote
3 answers
147 views

Array of a class or class with multiple property arrays

I have a simple question, why would I use an array of a single class over a class with multiple property arrays? Context: I have a series of calculators that extend off a base calculator. Each ...
user avatar
0 votes
2 answers
86 views

Why doing more than one thing in a class is sometimes valid? [duplicate]

classes and method should do one thing like the code below: class A { public int a() { b(); } private int b() { c(); } private int c() { } } The code mentioned below I found it ...
user avatar
-2 votes
1 answer
84 views

How to model a small database application using CRC

I am going through this OO design course: https://www.coursera.org/learn/object-oriented-design/home/welcome and starting to look at the use of CRC cards. (class responsibility collaborators). I ...
user avatar
  • 1,757
-1 votes
2 answers
194 views

Enum and Programming to Interface and best practices

I am learning stuff and have made 2 microservices, Listener and MyApp. Listener is a jms listener (consumer of messages) and MyApp is the app sending messages to queue. I have 2 type of events CREATE ...
user avatar
0 votes
1 answer
621 views

C# is it acceptable to create a generic class and use an enum as generic type?

Abstract The case: Application contains a lot of views with a list of data. Data views (lists of records) have pagination, filtering and sorting options. The user must be able to select a "...
user avatar
1 vote
1 answer
48 views

Page Object Model: Relationship between a page object and a driver

There's a question that struggles me for a long time already and so far I couldn't find or figure out a good answer. Hopefully, you will help me with that, folks. Before the story, a little background:...
user avatar
10 votes
5 answers
3k views

Pros and cons of representing routes as legs or stops?

What are some pros and cons of representing routes as legs or as stops? A leg is a departure and arrival location, a departure time and a duration (or an arrival time and a duration). A stop is an ...
user avatar
-1 votes
1 answer
63 views

Designing a class implementing a method which signature types depends on the instance contained

My goal is to define a Service class which process method accepts a RequestType argument that is defined by the contained ServiceType and returns an object of a type defined by ServiceType. By doing ...
user avatar
10 votes
4 answers
2k views

Can a class contain its own class?

Suppose I have the following class structure: A forest can have any number of trees, but each tree can belong to only one forest. If the forest is deleted, the tree is deleted. A tree must have at ...
user avatar
  • 219
-1 votes
2 answers
485 views

Initializing instance variables from json file

I have a class whose instance variables should be initialized from a file ('settings.json'). That file does not always exist or is sometimes not filled with useful values, so I have to check for that ...
user avatar
-1 votes
1 answer
52 views

Model design for `Team`s and `Member`s

Say we have to create a model for a company, where employees can be part of many different teams. A team can have member members. Members can be part of many teams. How to design database tables for ...
user avatar
  • 162
2 votes
2 answers
134 views

How to structure classes for two distinct use cases that share key parameters

I have a Java application that needs to generate mathematically-defined 3D shapes for a voxel world (Minecraft specifically, but that's not important to the discussion). These include sphere, ovoid, ...
user avatar
-1 votes
3 answers
433 views

Does wrapping functions/'things' in classes reduce efficiency?

I was reading some C++ object-oriented programming notes that mentioned that we should avoid wrapping functions in classes if it is not required, since wrapping 'things' in classes would reduce ...
user avatar
-1 votes
5 answers
289 views

Designing Entity Objects in OOP

I am newbie to programming and I am confused how to design an entity objects/classes. For example I wanted to create an animal kingdom in my application. Do I need to create a single Base Class (...
user avatar
  • 21
1 vote
0 answers
111 views

Is using C++ Classes to handle commonly used parameters a misuse of classes?

My team works on an HTTP web server in C++. The codebase has aged over time, and has a widespread problem of 12+ parameters being passed to every function. A fake example: We need to build a Car, but ...
user avatar
  • 231
0 votes
0 answers
183 views

Could you help me understand what a problem domain is and how can I build my class diagram based on it?

So I just started studying Software Engineering because I am really interested in it and my professor in London asked us to create an app which is like Instagram (only theoretically, without the ...
user avatar
1 vote
3 answers
168 views

Is it called "composition" if we are using primitive data types?

The following is an example of "composition": public class Car { Engine engine; // Engine is a class } But is it still called "composition" if we are using primitive data ...
user avatar
-5 votes
2 answers
346 views

How can you call a function from within a constructor when the contractor is defined before he function definition?

I have gone through multiple posts but am unable to find an answer to my very basic question on classes and so asking it here, it would be great if someone could shed some light on this topic- I have ...
user avatar
1 vote
2 answers
751 views

DDD: Aggregate root too many lines of code

I am following the DDD principles and have these Aggregate root classes. The problem is that after some time my class contains 1400 lines of code which makes development experience a little bit worse. ...
user avatar
-3 votes
1 answer
58 views

Should I design a class to handle my other class or the attribute of my other class?

Please allow me to illustrate my question with a simple example. Let's suppose we have a Customer class: class Customer: def __init__(self, name, surname, email): self.name = name ...
user avatar
4 votes
3 answers
223 views

Creating sub-classes of all external classes

I am in a team developing Android applications in an enterprise corporate .One of team members suggested that we should create our own classes, so extending every classes of UI kit (Material Design). ...
user avatar
2 votes
0 answers
34 views

Update class member gradually [duplicate]

Consider the following: import typing class MyClass(object): def __init__(self): self.my_member: typing.Optional[dict] = None def update_member(self): self.my_member = {} ...
user avatar
  • 129
0 votes
3 answers
2k views

Is throwing custom exceptions from private methods OK?

(I moved this question here, as StackExchange fits better, originally I posted it on StackOverflow.) This is not a question about a particular piece of code, rather I ask what is the right design ...
user avatar
  • 131
1 vote
3 answers
201 views

Is it a good practice for functors to store outputs as instance attributes?

The question pretty much says all, but let's look into a simple example (I'm using C++, but the question is not strictly related to any particular language): So, let's say that we have a functor that ...
user avatar
  • 137
1 vote
4 answers
729 views

Is a class with a high number of member variables bad and is there a design structure for data processing?

Context: Java, fairly new developer I have inherited code from a friend for a project that processes variables. The first thing i notice is the class has a ton of member variables. I have always been ...
user avatar
  • 127

1
2 3 4 5
9