Questions tagged [class-design]

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

Filter by
Sorted by
Tagged with
1 vote
2 answers
262 views

Why access the attributes of a Python class by reference?

Attribute references and instantiation In this link, that is part of the official Python documentation, I have found the following information: Class objects support two kinds of operations: ...
User051209's user avatar
0 votes
2 answers
171 views

For non-container classes, are "better naming" and "ready for commented codes" good reasons not to declare the most abstract type?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, but the question is about template class ...
wcminipgasker2023's user avatar
2 votes
3 answers
169 views

Class design using Open and Close Methods

As the title says, Im thinking if it's a good practise to have classes that have Open and Close methods in the sense that they can be reused without a new instance being created again. Also, if I want ...
Nmaster88's user avatar
  • 167
1 vote
2 answers
211 views

Is "declaring most abstract type" suffers from the same problem as "primitive obsession"?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), when creating objects, I should declare the most abstract type, eg : Map hashMap=new HashMap(). ...
wcminipgasker2023's user avatar
0 votes
0 answers
40 views

Class Composition For A List With Multiple Types

I have some classes like so class User{ Preferences List<Participants> BlueFontParticipants PropertyThatComputesFromAListOfParticipants<Participants> } class Preferences{ ...
Stevenfowler16's user avatar
0 votes
6 answers
769 views

Is it best practice for each call to a SQL Server to be in its own class, even when using dependency injection?

I often see/write classes that contain every part of the application where the application will talk to a SQL server. For example, you may have a class like this public class Data { private Func&...
J. Mini's user avatar
  • 1,007
2 votes
1 answer
169 views

Socket Class Design C++

I am currently trying to design some C++ classes that encapsulate POSIX sockets and their relevant functions. I want to try and design classes that are simple, elegant, and make the best use of design ...
nick2225's user avatar
  • 147
-2 votes
1 answer
258 views

Should I use function-based exports/imports or classes?

What would make more sense, to use functions for exports/imports: // globals/helpers.js exports.fnOne = () => {} // features/user.js const {fnOne} = require() Or class-based approach with static ...
WebrJohn's user avatar
3 votes
2 answers
226 views

Efficient way to Decouple classes in class design

I am working on a class design question - design a simple grocery store with a self-checkout system I am a beginner After briefly jotting down requirements, I started with the Product class as follows ...
darklion's user avatar
23 votes
5 answers
6k views

Best Practice - Avoid naming class and field the same?

When modeling classes I always have stumbled on the problem that the class has a field with the same name. Look at this example: class Name { string meaning; string language; string name; /...
bubbletea's user avatar
  • 347
0 votes
1 answer
119 views

How to handle root paths in a custom package?

I am writing a custom python package, which produces some files in a certain directory. This directory I call root_path and should be set by the user. So basically, it should be a conf variable but ...
Corram's user avatar
  • 103
1 vote
2 answers
544 views

Should I duplicate or inherit a python dataclass which changes attributes based on the version of an API endpoint?

I'm working on a python library for a REST API.I'm using python data classes to represent the structure of the returned JSON The v2 of this API returns a slightly different object when compared to v1. ...
rsn's user avatar
  • 117
0 votes
1 answer
105 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 ...
Ryan Folks's user avatar
3 votes
3 answers
225 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'...
Tim Kirkwood's user avatar
1 vote
2 answers
614 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 ...
Union3008's user avatar
1 vote
3 answers
279 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. ...
user3717741's user avatar
0 votes
1 answer
108 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 ...
Anon's user avatar
  • 3,593
0 votes
1 answer
573 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 ...
Florentin Alexandru Iftimie's user avatar
-1 votes
1 answer
2k 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 ...
WhoDatBoy's user avatar
  • 123
0 votes
2 answers
381 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 ...
ewhiting's user avatar
  • 329
0 votes
2 answers
187 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 ...
Nifim's user avatar
  • 151
0 votes
1 answer
2k 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" ... #...
a a's user avatar
  • 261
-1 votes
1 answer
117 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 -> ...
Phenomenal One's user avatar
-3 votes
2 answers
493 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& ...
Richard Bamford's user avatar
3 votes
5 answers
306 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 ...
Jojolatino's user avatar
4 votes
2 answers
824 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 ...
coney1's user avatar
  • 87
-1 votes
2 answers
94 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>> ...
Seonix's user avatar
  • 11
0 votes
1 answer
94 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; ~...
Martin Perry's user avatar
2 votes
3 answers
272 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 ...
SyncMaster's user avatar
1 vote
3 answers
250 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 ...
Alexis Pister's user avatar
0 votes
1 answer
110 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 ...
Karl 17302's 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 ...
Afia R. S.'s user avatar
1 vote
0 answers
143 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 ...
David's user avatar
  • 21
-2 votes
2 answers
229 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 ...
Alex Boorjs's user avatar
-1 votes
4 answers
684 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 ...
Lightsout's user avatar
  • 125
1 vote
3 answers
458 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 ...
S1r-Lanzelot's user avatar
0 votes
2 answers
93 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 ...
Sajied Shah Yousuf's user avatar
-2 votes
1 answer
127 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 ...
user619818's user avatar
  • 1,757
-1 votes
2 answers
253 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 ...
Akash Sharma's user avatar
0 votes
1 answer
3k 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 "...
user2190492's user avatar
1 vote
1 answer
71 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:...
ourgraciousruler's 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 ...
François Beausoleil's user avatar
-1 votes
1 answer
152 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 ...
Antonio Santoro's user avatar
10 votes
4 answers
3k 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 ...
Alan's user avatar
  • 219
-1 votes
2 answers
2k 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 ...
user69188's user avatar
-1 votes
1 answer
56 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 ...
funct7's user avatar
  • 162
2 votes
2 answers
137 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, ...
Excrubulent's user avatar
-1 votes
3 answers
1k 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 ...
The Pointer's user avatar
0 votes
6 answers
593 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 (...
jymskrl's user avatar
  • 31
1 vote
0 answers
118 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 ...
DonutGaz's user avatar
  • 251

1
2 3 4 5
9