Stack Exchange Network

Stack Exchange network consists of 174 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.

2
votes
3answers
96 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
359 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
473 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
346 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
259 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
23 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
384 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
53 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
224 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
114 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
168 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
354 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 ...
-1
votes
1answer
41 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
90 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
410 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 ...
0
votes
0answers
119 views

Compute and assign value to an attribute during class instantiation python

I am new to OOPs and don't have software engineering/computer science background. I am trying to define a class where I want to compute and assign a instance attributes under def __init__(): as ...
8
votes
6answers
986 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
180 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
131 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
67 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
88 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
909 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 ...
0
votes
0answers
162 views

Preferred way to implement protobuf-based classes in Python?

I'm working on a distributed application that will use protocol buffers as it's core interface definition language. While am amazed how pleasant protobufs are to work with in a networking context I'm ...
1
vote
0answers
83 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 ...
0
votes
3answers
3k 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
165 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
39 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
243 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
141 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
413 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 ...
0
votes
1answer
199 views

Is it a good idea to load all user data on top of each file including sensitive information?

I've written a User class like this: <?php class User{ private $id; private $username; private $password; private $name; private $email; private $key; private $phone; ...
1
vote
1answer
96 views

How to verify that every object responsible for Itself

I wonder if I have multiple objects and how to list their responsibilities where every Object Must be Responsible for Itself for example: If I have three objects: Employee,Schedule,Shift. and ...
0
votes
3answers
2k views

C++ design - vector classes with different element types

I am trying to design a group of related classes. For example: one table class holds a vector of integer, and has a function returning integers from the vector another table class holds a vector of ...
27
votes
3answers
5k views

Optional parameters or overloaded constructors

I am implementing a DelegateCommand, and when I was about to implement the constructor(s), I came up with the following two design choices: 1: Having multiple overloaded constructors public ...
1
vote
1answer
462 views

Using inner classes to achieve thread-safe behavior without synchronization

I have some classes that contains both immutable (primitive & references) and mutable data, but mutability come from external writes (another process). To avoid using synchronized on every ...
0
votes
0answers
37 views

Is it bad practice to not separate the class definition and constructor into separate files? (specifically in R package development)

I am developing an R package and for some reason all of the current packages I have looked at put the class definition and class constructor in separate files. Usually a myClass--class.R file and a ...
1
vote
3answers
230 views

How to define sound playing function? one single function for all sounds? or each sound has its own function?

After many years, I still unable to determine the correct way to define a class/function to play sound. Suppose my app may need to play some sounds, for example: button click, error popup,... How ...
2
votes
1answer
88 views

Feedback on inheritance assignment

So I've got this java assignment for college and was just wondering if anyone here could give me some feedback as to what I've been thinking some of this means. I've got a .csv file with building ...
1
vote
0answers
100 views

ES6(babel): Best practice for create class

I have a Product class. When I attempt to reference this from within a method on the class, I get an error saying this is undefined. To solve this, I have to bind this to all methods. And this, for ...
-2
votes
1answer
104 views

Splitting up a class

I have a Report class that is basically an interface for creating HTML reports generated via a Python template engine. The Report class currently generates the report but also has a few methods ...
0
votes
2answers
78 views

Hashable classes: Should I only keep the id's for results or entire class

Given 2 objects / classes: A class for a cargo ship. It has a small set of attributes, say current location, size, number of crew and some other things. Most important, it has an attribute for the id ...
14
votes
3answers
555 views

Can the RxJava class Flowable legitimately have 460 methods?

I am just getting started with RxJava, Java's implementation of ReactiveX (also known as Rx and Reactive Extensions). Something that really struck me was the massive size of RxJava's Flowable class: ...
7
votes
3answers
1k views

How to use 'Adapter' without any changes in the existing code in c++

Here we have TV class and DVD class as example: class TV { public: TV(); virtual ~TV(); void on() const; void off() const; }; class DVDPlayer { public: DVDPlayer(); ~...
1
vote
1answer
154 views

Mediator pattern or facade or …?

I'm writing an app which tracks device location and based on some factors (user gets an assignment), it needs to change the location tracking settings (for example, frequency). I have an issue with ...
4
votes
2answers
314 views

Identify methods on OOP

I am struggling to define methods in OOP. Currently I am practicing with this scenario: "A hospital has started the development of a new system to keep records of analysis done by patients and the ...
4
votes
6answers
305 views

Exposing member variables vs Adding member functions to modify them

Say that we have a class Car that contains objects of type Wheel class Wheel { public: void SetFriction(double f) { friction = f; } private: double friction; }; class Car { ...
3
votes
2answers
155 views

When to use a repository/service vs an instance variable?

When does an object truly belong to a class? I'm familiar with the "has-a" relationship, but in the case of an Employee object, it "has-a" 401k, but it's not really composed of a 401k object. As an ...
0
votes
2answers
179 views

Where should I put the database access method in a treeview environment

I have written a class to represent 'Treeview-like' data, which can be simplified as: public class Item { public string Name { get; set; } public KPI AssociatedKPI { get; set; } public ...
1
vote
1answer
105 views

Should repeatedly-computed quantities derived from member data be stored in member data containers?

This question is generally regarding when it is a good idea to store quantities derived from member data in, say, std::vectors that will be repeatedly computed/accessed in various methods, but I will ...