Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [class-design]

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

-3
votes
1answer
82 views

What do the different access categories in C++ classes do? (Private, public, and protected) [on hold]

I have been trying to learn about classes and objects in C++, but every tutorial I have found is quite complex, at least to my standards, and I really would like a really simple and straight forward ...
1
vote
1answer
63 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
4answers
157 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
178 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
128 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
208 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
71 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 ...
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

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
148 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
305 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
206 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
146 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
73 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
100 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(...
2
votes
5answers
269 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 ...
1
vote
1answer
123 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 ...
0
votes
0answers
53 views

Getting into situations that requires mixin while building classes. How should I correct my class design?

I have the following classes for to solve a particular problem related to HTTP responses. Problem is for class ServerSentEventStreamResponseService I am in a situation where I need mixin because I ...
1
vote
2answers
161 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
43 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
votes
2answers
217 views

“private methods” vs method out of class in a python module

I have a module with the class Foo. Foo has three methods: The constructor(__init__()) An error handling method (_error_handler()) The method that actually does something. (run()) Then, I have a ...
2
votes
3answers
138 views

How to store objects with inconsistant properties

I have real-world materials that are defined by various properties, some common, some not, that I would like to map to objects in C#. For example, Concrete has properties A, B, C, and Metal has ...
14
votes
7answers
6k views

Is it a bad idea have make a class method that is passed class variables?

Here's what I mean: class MyClass { int arr1[100]; int arr2[100]; int len = 100; void add(int* x1, int* x2, int size) { for (int i = 0; i < size; i++) { x1[i] +...
7
votes
2answers
386 views

Class that returns multiple unrelated values, are there better way to accomplish this?

I have a "tracker" class. This class tracks objects from a given input image. But in addition to this, there is another parameter that corresponds to a value used in generating the image. The ...
0
votes
1answer
623 views

Why does the Square–Rectangle problem violate SOLID principles?

My previous question was just with class diagram and because of some comments I thought I try to find an example with a little piece of code for the diagram to see if principles correct understood? ...
1
vote
2answers
439 views

Which SOLID principles are broken by this class diagram?

I just read about all the 5 principles S,O,L,I,D and I like test it in little example if I understand them correct. Which SOLID principles are hurt by this class diagram? I think what is broken is ...
4
votes
4answers
315 views

Is it a good idea to put in a bunch of static functions that are related to each other in terms of scope inside a class?

The language is PHP. I have several functions that relate to each other (and sometimes use each other) that I've decided to couple under the same class. Here are my reasonings, do keep in mind that I'...
-2
votes
1answer
25 views

Data Sharing Levels of Privacy

I've been looking through class and friends and similar c++ arrangements to share data, and cannot find how to program levels of share. No players can know what the other players have in their gold-...
2
votes
2answers
394 views

Is it bad practice when an Object has to be aware of another Object

I was reading this page and came across this sentence in the accepted answer: I don't like A directly knowing about B. But that's a DIP thing not a POJO thing. What if you can't abstract out B ...
1
vote
1answer
66 views

Should I group all sound file definitions together? Or define some of them locally, if possible?

For example, suppose my application have some sound files, now I define all sound file references in a single class: public class SoundHelper{ public static Sound buttonSound=new Sound("(some url)...
1
vote
2answers
241 views

Liskov Substitution Principle

I am trying to wrap my mind around a Liskov Substitution Principle and I came across this article. SOLID Class Design: The Liskov Substitution Principle In this article, the author gives an example ...
0
votes
1answer
165 views

How should I separate File Parse Classes?

I want to understand different ways to object design classes. I have three different classes. Generally I am creating a file parser. The classes: CustomerData - which shows text Data Model. A File ...
4
votes
2answers
198 views

Verifying Parameters in Constructor or Service

I was reading on this SO page about when to check parameters when constructing an object. The accepted answer suggests throwing the exception from the constructor so that an invalid object cannot be ...
1
vote
3answers
360 views

When to use Parameters and When Not to C#

I am have an application using MVVM pattern. It takes a user ID and returns a table with the user's bookmarks. I am trying to decided if it is better practice to include parameters in my model's ...
0
votes
1answer
55 views

Is it good practice to use data API for access cross platform

All, Question: Should I have a common data access API between various cross platform applications or keep the data access specific to the UI even though it would result in duplication? Background: ...
2
votes
2answers
104 views

Should methods be part of your persisted entities?

We are coding a small game and have a Player class. This Player class has certain properties which you would persist in a database like Id, Level, Health. We would like a Player to be able to kill ...
3
votes
4answers
439 views

Is Abstracting your code too much a bad use of SOLID Principles?

After an unresolved argument with a friend I decided to ask the stack overflow community. Is there something like abstracting your code too much? Which of the following is the better option. We come ...
8
votes
6answers
1k views

Should reused exceptions types be favored over single use ones?

Let's say I have Doors that are managed by a DoorService. The DoorService is in charge of opening, closing and locking the doors that are stored on the database. public interface DoorService { ...
2
votes
1answer
181 views

Best methods to account for large block of variables?

The question sounds retrograde but I have about 50 variables being passed to a class. Basically an array of data I call 'filters' that is first passed to a prepFiltersMethod($filters). This prep ...
0
votes
1answer
259 views

Enum as part of domain - enum + extension or consolidate into one class?

I have a program where the domain is focused around programs. As part of the domain, I have a 'ProgramType', which is an enum formed mostly via a string from the database but also via a bit of logic. ...
2
votes
1answer
68 views

Should we use multiple inheritance to redefine X() and call inherited X() from each superclass?

We have 4 classes. Field ForbiddenField inherits from Field RequiredField inherits from Field ForbiquiredField : the subject of my question I would like to define a function Validate()in ...
0
votes
2answers
91 views

Class design : Decide between file and database for storage during runtime [closed]

Based on the demo or license version of my application, I am supposed to either save the data to a file (xml) at a specific location or a relational database. What should be my approach for this case ...
1
vote
4answers
980 views

What is the proper place for complex business logic

I have an object that describes a two-dimensional Graph: class Graph { var points; // Array of points } Now I need to find some complex patterns in this graph, like (but more complex): Find two ...
1
vote
0answers
198 views

Putting the rowmapper inside the domain class

Normally in java the RowMapper is placed in its own class. Instead, what about this design, putting the RowMapper inside each domain object, and giving all of them a consistent name: public class ...
2
votes
3answers
14k views

Best way to naming classes and packages in Java

Apart of the code conventions to use camelCase, PascalCase etc., are there any conventions for naming packages and classes in Java? For example, I have an mvc project and the main package is com....
1
vote
1answer
183 views

Limitations of using classes as interface

I am an Electrical Engineer now training and working as an embedded software developer, so I have little formal computer science and software design training. I have until a few months ago only worked ...
0
votes
1answer
47 views

Bill Splitter application UML Design

I just want to improve this design, share your thoughts. Q1. I have specialized Splitter class based on monetary unit as "MonetarySplitter" and "NonMonetarySplitter". Whether doing so is correct? To ...
0
votes
1answer
373 views

Representing Java Object Hierarchy With Nested Classes

I was working with some API which was used internally, and while looking at their code I found something like this: public class Parent { @Data public static class Child { private ...
0
votes
2answers
147 views

Class design - Inject data or inject repository/service to fetch data?

Let’s say for example I am developing a fictional class called WidgetMaker. If the class depends at some point on lookup data stored in a database is it better to design the class with a dependency ...
0
votes
1answer
556 views

Controller and API DTO Architecture and class organization in .net core with microservices

We are developing a system with coarse microservice architecture. We have an API that uses controllers and back-end logic with Entity-Framework repository, and several types of clients that use this ...