Questions tagged [class-design]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
61 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 ...
1
vote
3answers
178 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 ...
0
votes
0answers
37 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"...
0
votes
1answer
87 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 ...
1
vote
1answer
65 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 ...
0
votes
0answers
74 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 ...
-2
votes
2answers
180 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 ...
-2
votes
4answers
209 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 ...
1
vote
3answers
139 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 ...
0
votes
2answers
80 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 ...
-2
votes
1answer
67 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 ...
-1
votes
2answers
175 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 ...
0
votes
1answer
226 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 "...
1
vote
1answer
46 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:...
10
votes
5answers
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 ...
-1
votes
1answer
38 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 ...
10
votes
4answers
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 ...
0
votes
0answers
146 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 ...
-1
votes
1answer
51 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 ...
2
votes
2answers
131 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, ...
-1
votes
3answers
259 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 ...
-1
votes
5answers
216 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 (...
1
vote
0answers
105 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 ...
0
votes
0answers
123 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 ...
1
vote
3answers
147 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 ...
-5
votes
2answers
147 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 ...
1
vote
2answers
390 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. ...
-3
votes
1answer
56 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 ...
4
votes
3answers
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). ...
2
votes
0answers
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 = {} ...
0
votes
3answers
1k 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 ...
1
vote
3answers
179 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 ...
1
vote
4answers
469 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 ...
-10
votes
1answer
101 views

Find design issues via a class diagram? [duplicate]

Given a class diagram , how can we find design issues in it. I am not talking about the relationships it should be representing as they exist in the real world but i am talking about design issues ...
0
votes
3answers
318 views

How to find design defects by using a class diagram? [closed]

What are the design defects that can be spotted by using a class diagram, and how? I am not concerned about syntactical/ representational defects, but in things like the following: Do the classes/...
-2
votes
1answer
92 views

should the join method be in the Course class or the Student class?

The rule I was taught: "the method should be in the Object that it is invoked on" a student joins a course => the join method should be in the Course class a player drives a car => car.drive(..) ...
1
vote
4answers
246 views

Is there multiple definitions for responsibility of class?

In the book UML 2 and the Unified Process from Arlow and Neustadt has been told: Analysis classes should have 3 to 5 responsibilities But as you know we have the SRP that tells us something else!! ...
0
votes
1answer
78 views

Inheritance but with two different shared traits?

I am facing a dilemma with designing an api gateway. Currently, I am using the pipeline pattern, with different stages being the requests made to various services, (http, sockets, amqp, ...). I have ...
1
vote
1answer
266 views

Design Chess - Object Oriented Design

I am trying to design online chess game(figuring out required classes). Need some suggestion on choosing better option to validate the move. So, lets say, I have below class Option 1 : My ...
2
votes
0answers
50 views

Javascript module design patterns

Partly for use in my own projects, and partly for fun while being stuck at home I'm attempt to build yet another "block" based editor. So far I've been using simple objects, starting with a global ...
-1
votes
2answers
93 views

What are the guidelines for using attributes vs. passing local variables along from method call to method call?

What are the OOP best practice guidelines - in general or specific for ABAP - for using attributes to store data versus just passing it along as method parameters. I'm having a hard time deciding ...
2
votes
2answers
230 views

The usage of getter notation inside the context of the class

Consider the following JavaScript code: class MyClass { #myPrivateField; constructor() { #myPrivateField = new AnotherClass(); this.theGetter.method1(); // or: this.#myPrivateField....
1
vote
4answers
207 views

How to avoid global mutable variables within a class?

I know the fact that global mutable variables are bad as they can be accidentally modified and make testing difficult. However, there are situations when a class needs to cache some information, for e....
0
votes
0answers
106 views

"Best practice" or "design pattern" to group a class with "associated" classes in an object-oriented language

Sometimes a class A can have an "associated" class B such that the implementation of B depends on the implementation of A. For example, this can happen when B's objects are to be created by A's ...
2
votes
2answers
130 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 ...
0
votes
2answers
260 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
154 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
909 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
5answers
279 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
391 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; } ...

1
2 3 4 5
9