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

learn more… | top users | synonyms

3
votes
2answers
72 views

Introducing behavioural differences in a complex domain model

Assume we are building a system for managing large, tree-like domain-structures like banking loans or insurance contract. At the root of the domain model is a Loan class. It serves as an entry point ...
5
votes
1answer
59 views

Python - Architecture for related instance attributes

I want to preface this question by apologizing for its length, especially the code samples; however, I believe I have included the minimum necessary code to illustrate the differences in approaches. ...
13
votes
4answers
542 views

Large class with single responsibility

I have a 2500 line Character class that: Tracks the internal state of the character in the game. Loads and persists that state. Handles ~30 incoming commands (usually = forwards them to the Game, but ...
1
vote
1answer
111 views

Can the has-a relation in OOP become ambiguous or difficult to know?

Assume I have the following code. class D { static Integer i1 = 42; } Is it true that D has an Integer? Or is it only for instance variable that we can have a has-a relation? I also wonder about ...
0
votes
2answers
77 views

How to handle “reverse dependencies” between classes with proper object-oriented design?

I'm trying to learn proper object-oriented design, with class relations and avoiding anemic domain models[1]. I'm creating an application to store and retrieve information about "cyberattacks". There ...
3
votes
1answer
78 views

Contract interface/class with inner classes/interfaces

Brief description of my project structure. I have some base classes like BaseView, BasePresenter ... . Also my project consists of modules, module represents one complete part of the application. ...
3
votes
2answers
86 views

Using PHP traits to simulate multiple inheritance

For this question I want to present my current design and my idea of using a trait. I would like to know whether my understanding of traits is correct and whether my problem can be solved with another ...
0
votes
0answers
41 views

Dividing up a large class into tasks - passing `this` when creating helper classes

For classes that expose an interface to the outer world, I observe that callbacks are used as a standard interface. For child helper class objects that are tightly integrated to its parent, I want to ...
4
votes
5answers
202 views

Should I encapsulate an object inside another object as methods or just access it directly?

Suppose I have a class: public class A{ public void a(){ } } and class B use A: public class B{ private A a; } Should I encapsulate A in B: public class B{ private A a; public ...
5
votes
3answers
132 views

Should I put UI and logic in separate classes?

I currently work on a hobby project which I use to learn more about Android/Java programming and programming in general. Recently, I decided to integrate jUnit into the project. Just getting it in ...
5
votes
1answer
92 views

I have a class for creating objects from a database row. How to design a class to perform functions on all rows e.g. counts on db table

Say I have a database for storing cars data. Each row is essentially a car and I've a class that takes a row of the data and builds my car object. I now want to build a dashboard that can tell me all ...
47
votes
6answers
5k views

What would be the disadvantage to defining a class as a subclass of a list of itself?

In a recent project of mine, I defined a class with the following header: public class Node extends ArrayList<Node> { ... } However, after discussing with my CS professor, he stated that ...
5
votes
2answers
123 views

Should I use a huge delegator to keep my code decoupled?

I am currently learning to apply the SRP and decouple code. But I found that having a lot of small classes blows up constructors of my classes. And it feels like code that uses another module of my ...
3
votes
2answers
119 views

How to build a class for comparing words in a lexical dictionary?

I'm wanting to create a class that stores words in a set so that I can see if a word belongs to that set or not. I'm not wanting to build ever set every time I instantiate the class, so I'm using what ...
1
vote
2answers
45 views

Proper event driven design when a consumer subscribes to many producers

I have a large number of instances of a class. Those instances can fire an event. The only important thing for that event is which instance fired it. I have another instance of a class (and maybe in ...
-1
votes
1answer
84 views

abstract classes or other generalization classes?

i have a question about software engineering best practice. Let's consider a class "User", with 2 subclasses "Student" and "Teacher" if we need to specify some data for "University special council" ...
1
vote
0answers
58 views

When to make classes that do multiple things? [duplicate]

When is it advisable to write a class that can do multiple things? A bit of background: my boss prefers to write things that can be used over and over again. While I tend to agree with this sort of ...
5
votes
1answer
86 views

Reusing a top-level DTO as a child in another DTO

What is the recommendation regarding re-using DTO's as a child in another DTO? I'm using ASP.NET Web API (C#) and consuming the results with Angular 1.x (not sure if that really matters). I have the ...
0
votes
2answers
88 views

Creating instances of an ability when there are multiple different type of abilities

I'm creating an RPG game where a player has a set of skills, each of which he can level up to improve its effect. Here are two example skills: health: increase player's maximum health regeneration: ...
1
vote
3answers
316 views

C# / Java: Should every class have a main method?

I've been learning C# lately to see the other side of the coin (I have a decent amount of Java knowledge already) so I've been reading up on C#, and I came across an article called C# for Java ...
5
votes
2answers
641 views

Design patterns for creating objects that have a list of objects that also have a list of objects

In terms of good OOP design, what is the best way to structure code that is just containers of list of objects that contains other lists of objects that also are just other containers? Example: A ...
1
vote
2answers
100 views

Dependencies between class attributes

I wonder whether there is a concept for attribute dependency in object oriented terminology? It's an example showing what I mean with attribute dependency: 2DShapeclass may have an areaattribute. ...
2
votes
2answers
177 views

What would be the proper way to design the class hierarchy here?

I am writing a "hunting-ground" application in Java. I planned the hierarchy of classes as follows: Animal.java public interface Animal { void age(); void reproduce(); boolean isAlive(...
0
votes
0answers
42 views

Two classes or One when maintaining Invariant and allowing De/Serialization

I am facing tough time deciding on whether to have two different classes in system, one for keeping class invariant and other for (de/)serialization or to just have a single class which does both. ...
2
votes
1answer
32 views

Which option for class initialisation/design

I have a class Game. This class needs to take three arguments passed in it's constructor: List of game pieces Board Size Game piece placement 'engine' I am dithering about the design of the game ...
1
vote
1answer
80 views

Controlling a sensor network

I am having a problem developing an object-orientated architecture to manage a network of sensors and controls. Currently, I am writing in Python, but this is more of a conceptual question. I have an ...
3
votes
2answers
241 views

Eliminating cyclic dependency

I want to avoid cyclic dependency in this schema: DbRepository needs IUserDbEntityFactory to create User entity which needs IUserPublishedInfoInitializer to create UserPublishedInfo on request. And ...
2
votes
2answers
174 views

REST API design with big (detailed) and small objects

We're facing the issue that we often have classes with lots of properties. But we don't need them for most API calls. So we end up having multiple versions for basically the same business object. E....
0
votes
3answers
233 views

When NOT to use a class / member variable?

I am trying to learn WHEN NOT to use: classes member variables HERE IS THE CODE access_point_detection_classes.py from scapy.all import * class Handler : def __init__(self) : self....
0
votes
2answers
63 views

Object Oriented Python methods and their parameters

Let's say I have a class MyClass ... which has a data member x class MyClass1 : def __init__(self) : self.x = 1 Also a method which does something with x Should I pass self.x as a ...
0
votes
1answer
98 views

Seeking advice on design strategy for Java application

I'm a very new programmer developing my first application in Java as a side project for my employer. I'm a part-time student working full-time hoping to eventually score a developer job, and my ...
10
votes
3answers
908 views

How should an `Employee` class be designed?

I am trying to create a program for managing employees. I cannot, however, figure out how to design the Employee class. My goal is to be able to create and manipulate employee data on the database ...
0
votes
0answers
35 views

Choosing class names and relations for different user scopes

I am developing an online Order Management System using PHP in which I have some different behavioural scopes regarding the User class: some user scope under which the chronological transactions are ...
0
votes
1answer
93 views

Example of class modeling

This is in the continuation of Small classes and methods, but code still difficult to maintain and follow as I have matured the problem and will rebound on people's answers. Here are all the elements ...
0
votes
0answers
38 views

validating arguments in javascript constructors

In many cases, it is useful to have a constructor or factory method that validates arguments before instantiating an object, returning a new object if the arguments are valid and null otherwise. But ...
1
vote
0answers
70 views

Two classes which are supposed to be the same, but differ in lists

I am using a 3rd party API which yields JSON which has two ways of loading data - as a list of items, or as a singular item. The problem is that a given item in the list has different properties than ...
1
vote
3answers
313 views

Define C++ class in one or more files

When creating a C++ class what is best practice> Put the entire class definition and member functions in a header file Put the class definition and function declarations in the header file and put ...
0
votes
0answers
33 views

Better way to model parallel implementations of specialised collection-like types

I am working with some wrappers for selection widgets on the web (in Selenium). They each have one "parent" type that represent the widget and another type for the options. Two interfaces are created ...
2
votes
3answers
189 views

Giving a class many constructors and assigning via them as many properties as possible

I have written a class which represents a SQLite Trigger. public SQLiteTrigger(string Name, string On, TriggerStartType StartType, ...
14
votes
4answers
1k views

How specific should the Single Responsibility pattern be for classes?

For example, suppose you have a console game program, which has all kinds of input/output methods to and from the console. Would it be smart to keep them all in a single inputOutput class or break ...
90
votes
13answers
12k views

How to warn other programmers of class implementation

I'm writing classes that "must be used in a specific way" (I guess all classes must...). For example, I create the fooManager class, which requires a call to, say, Initialize(string,string). And, to ...
0
votes
3answers
283 views

Using nested private class to hold data from csv file

I have a class that only has one method. This method has to read csv file, do some work concerning internal logic (check if item already exists, do some transformations, etc.) and finally write all ...
8
votes
2answers
1k views

When and why to use Nested Classes?

Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience. What are nested ...
0
votes
2answers
204 views

Per my design requirements, does this design hierarchy seem reasonable?

Background Construction Note that I am using C# here, but it may not be necessary to provide input to my conceptual questions about design. Consider the following design methodology... I work at a ...
9
votes
4answers
748 views

How to argue against this “completely public” mindset of business object class design

We're doing a lot of unit testing and refactoring of our business objects, and I seem to have very different opinions on class design than other peers. An example class that I am not a fan of: ...
1
vote
1answer
371 views

Multiple instance of the same class?

I have a class named "Category" to handle all the operations and data about my categories. Now, my class is created however I need to find a way to build an object for each of the categories in my ...
2
votes
3answers
152 views

Design of object alias

Suppose you develop an interpreter or file system. There are objects, like variables, procedures and files in some environment. They have a name and content (variable has current value, procedure has ...
1
vote
1answer
49 views

Does having a EntityBase or DomainBase class violate LSP?

Suppose we have a abstract class EntityBase which is the base class for all our entities e.g. public abstract class EntityBase { public Guid Id {get;set;} } public class Customer : EntityBase { ...
2
votes
1answer
288 views

How to avoid having nested generic in class

I'm working on a side project, and I turned on all rules for code analysis in Visual Studio, and I got the warning notice: Warning CA1006 Consider a design where 'Vote<T>.CalculateWinner(...
-4
votes
4answers
268 views

Splitting one class into subclasses to save memory

Suppose that you describe programs, which have a lot of AssignmentStatement(target, /*value*/Expression). There are other statements, like if-statement and for-statement and all of them may have ...