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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

0
votes
1answer
25 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
83 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
367 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
55 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
962 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
176 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
109 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
63 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
86 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
825 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
53 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
44 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
304 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
154 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
33 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
126 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
134 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
244 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
95 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
1k 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 ...
26
votes
3answers
3k 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
309 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
35 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
229 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
85 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
83 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
103 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
77 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
482 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
130 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
299 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
251 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
150 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
167 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
99 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 ...
7
votes
4answers
2k views

Using vectors of shared pointers to objects in my C++ code to prevent object duplication

In my C++ project, I have three classes, Particle, Contact, and Network. The Network class will have N particles (std::vector<Particle> particles) and Nc contacts (std::vector<Contact> ...
10
votes
5answers
3k views

How to resolve class interdependence in my C++ code?

In my C++ project, I have two classes, Particle and Contact. In the Particle class, I have a member variable std::vector<Contact> contacts which contains all contacts of a Particle object, and ...
0
votes
2answers
108 views

How to the refactor the following parallel code to avoid redundant checking?

In the following code sample, the processes are assigned to different contexts. And each App object will be bound to only one context. Though all the processes run the same code, only those belonging ...
0
votes
1answer
381 views

Is it good style to use private void member functions in C++?

I am currently writing a class that performs a rather complex computation that should be triggered by one function call. The steps of using the class would be: Construction including the ...
2
votes
1answer
80 views

Designing a complex user status model

I'm writing a program with the following conceptual mode. A User can apply to become an employee, which places their account in a Pending state. They can then be Approved or Rejected. The only ...
0
votes
0answers
128 views

How to make a proper argument manager for CLI Software?

I thinked about an ArgumentManager class working like this: A constructor with argc & argv(or std::vector) as parameter. getCount() => Returns argc. getArgLit(argLit) => Return true if the ...
1
vote
2answers
265 views

Deliveryman's position (latitude + longitude) handling on PHP server side from Android app

The context As a school project, I'm building a PHP and Android app for a fake company. Let's call the company "Express Food", which can talk pretty much by itself. The "daily meals" are kept by ...
2
votes
1answer
110 views

Private member variables: set via return value of a private member method vs modify within the method's body

I have read a lot of materials regarding preferring returning values from function like this: some_class func(); over getting output by passing it by reference like this: void func(some_class& ...
-1
votes
2answers
122 views

How do I provide a “template” for a class when I can't use a base class and don't need an interface?

I have a couple of derived classes that are generally similar, but don't have a directly shared base class. All these classes implement a common interface. I noticed when I added another (new) derived ...
0
votes
1answer
82 views

Moving interfaces but not concrete classes

Recently I started working on creating a client library. One problem which I am facing now is that I have to move the below interface Attributes to client library but the concrete classes (business ...
0
votes
0answers
309 views

C# EntityFramework 6 DbContext and data service with dependency injection

I am refactoring an application that collects and displays measurement data that is stored in a database. Currently I have an interface calleIMeasurementsDataService and an implementation ...
0
votes
0answers
71 views

Designing a specific class and using generic components

I'm struggling with a few classes I'm designing. To generate (HTML) tables, I came up with a GridBuilder. This GridBuilder loops through a collection of items and creates a Row for each iteration. ...
2
votes
2answers
823 views

Use of public typedefs in template class types

Recently I picked up the habit of typedefing various types within template classes, as is done in the standard library. For example, a container class might look something along the lines of: ...