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

learn more… | top users | synonyms

0
votes
1answer
14 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
votes
0answers
45 views

What classes should I use for API -> logic -> API?

I need to fetch some information from an API, parse through it and push the relevant data to another API. How should I design this? One class handling everything? One class per API and one for the ...
1
vote
1answer
34 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 { ...
1
vote
1answer
68 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 ...
-4
votes
4answers
193 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 ...
0
votes
0answers
21 views

Designing a (Spreadsheet) Report Class for Excel

A lot of my time is spent getting data into VBA, analysing it and printing it out again in nicely formatted Data Tables. This is my fist draft of designing a Class Object to handle Array Data ...
1
vote
1answer
41 views

Repository Pattern Class Collection examples with Lazy/Eager loading

When implementing the repository it's fairly easy for a stand alone class. Unfortunately, we are unable to use an ORM to manage our data access, so I'm trying to recreate some of the functionality ...
2
votes
2answers
30 views

Exception Handling for class attributes in setters and constructors [closed]

I would like to discuss a question about best practices regarding exception handling (e.g. in Java). Normally, when setting the attributes of a class, I check the arguments in the setters for ...
3
votes
2answers
102 views

How can I create extensible reader and writer wrappers around a shared opaque resource class?

In C++, Say I have a Buffer class (cannot be inherited) which is given and can support the following operation: class Buffer { public: void write_buffer(Data); Data read_next_data(); }; Now ...
2
votes
1answer
175 views

Helper methods of a particular class [closed]

Let's say I have a class that needs some helper methods to do its work. The number of helper methods starts to grow and the size of the class also starts to grow a lot. How should I handle this ...
1
vote
2answers
131 views

Acceptable design to use public member objects in composition?

Say I have a large class called Root, which has a lot of members & functions: class Root { public: void func1(); // operates on a and b void func2(); ... private: A a; ...
-2
votes
1answer
108 views

Should objects with different properties (not behaviour) have different types?

I see a lot of classes that look like: class Student extends Model { public string major; public string minor; } class Employee extends Model { public string department; public ...
1
vote
3answers
114 views

How To Extend Parent Methods in Children Classes?

There is a parent class with a method which many children use but many children extend the method, what is the best way to extend it without violating DRY? Here are my 2 current solutions: 1: The ...
5
votes
1answer
90 views

Object-Oriented design to create Images in Python

I'm creating images with centered text. I use Python but I'm faced with many question regarding how to write my class. I know that A class must aim to do one thing and do it well. Well, the ...
2
votes
3answers
88 views

Is there particular circumstance that throwing root superclass exceptions is a good practice?

I've been taught that exceptions should be have concise meanings and should contain a message that explains to the client what the exceptional situation is. I am wondering, since I found a piece of ...
0
votes
1answer
110 views

Should I hold an Id and the Item [duplicate]

Let's say I have a Customer which contains an Address class like: public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; ...
0
votes
2answers
78 views

ID in class diagram

As far as i know, we do not add an attribute like id to the classes in the class diagram. right? But when we create a database, or when we want to call an instance, we need its id, so why do not we ...
1
vote
3answers
155 views

How should you look at unit testing protected members used by the abstract base class?

I have the following class(es) that I want to write unit tests for: public abstract class BaseClass { public bool IsFooBar(Order order) { return order.IsNew && ...
-3
votes
1answer
86 views

Managers vs Repositories [closed]

I am having trouble naming classes as I am not sure when to use Repository or Manager in last of a class name. Are there any rules around these classes ? to me they mean same. For example if we have ...
0
votes
2answers
66 views

What is the difference between proxy class and delegation in Python?

Wiki: A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, ...
1
vote
2answers
202 views

To god (class) or not to god? [duplicate]

I'm working on a project that requires several different users in the system, all of which have overlapping responsibilities; we've isolated two possible ways of tackling this problem, but we're ...
1
vote
2answers
403 views

Class design for writing multiple versions of multiple files

I am writing a web service in Java which reads some information from a DB and generates multiple JSON files which are written to S3. For each type of file, I have a POJO which is serialized to JSON ...
3
votes
2answers
155 views

Designing my classes with relationships

I need to build a UI for entering values to the database. I am stuck with my class design to achieve it. I need a UI where I am able to enter the name of the system. Each system can have many ...
13
votes
4answers
3k views

Singleton or instantiate everytime I use? [duplicate]

I use a class that just extracts data from one known object, and distributes it to other known objects. No persistent configuration or such is needed in that class instance. How should I decide ...
3
votes
1answer
64 views

CharSequence to represent a named object

I always followed the opinion to not abuse interfaces in case of decomposition. Usually I only implement them if I am absolutely sure to have a "is-a"-relation and avoid implementing them if there is ...
2
votes
2answers
166 views

Class with only one execution

I'm implementing a long algorithm (about 500 lines of C++). The algorithm consists currently of about 10 different methods. Each method I have to hand over multiple data-structures as parameters, ...
1
vote
2answers
81 views

Using Entity Framework, non-MVC project, need help with class structure

I'm working on a very large non-MVC project utilizing Entity Framework for database access. This is a new project, so we've got a wide-open canvas for development. The conceptual problem I'm running ...
0
votes
0answers
47 views

Organising code in X++ where all classes for the application are in one long classes list

I am just beginning to develop in Dynamics AX 2012, using X++ (my background is .Net). The development environment in the application stores all classes for the application in one long classes list. ...
0
votes
2answers
165 views

How should I structure these Python classes?

Base Class I have a class called Remote. This class represents a remote machine and has properties such as ip, hostname, username, and password, as well as methods for transferring files to/from the ...
4
votes
2answers
646 views

Python classes with only one instance: When to create a (single) class instance and when to work with the class instead?

Given a Python class which will be instantiated only once, i.e. there will be only one object of the class. I was wondering in which cases it makes sense to create a single class instance instead of ...
2
votes
2answers
188 views

How to avoid god controller classes and keep single responsibility principle?

The task is to make a migrator from Old DB to New DB using OOP Single Responsibility Principle. My problem is how can I make this without making the controller a God Class or breaking the single ...
2
votes
1answer
121 views

Implementing a series of independent Actions that are disparate but with common accessibility

I have a requirement to implement a type of AI for a project, the issue is that I am having trouble visualizing how the AI should actually be implemented. Essentially, I want the AI to be as dynamic ...
0
votes
2answers
236 views

Why 'class String' definition has 'final' modifier? [duplicate]

This answer gives an indication that class String is declared final for thread safety, which does not convince. This answer does not convince when it says: And so, you make the classes final. There ...
0
votes
0answers
24 views

Math formula class in Java [duplicate]

I need to calculate a score based on various attributes of a Thing t. How should I implement the class that calculates this? Option 1: public class Calculator { public static int calculate ...
0
votes
0answers
11 views

What's a way to encapsulate “mapping” code and provide reusable functionality in a base class?

I have created a set of repository base classes, using the generic repository pattern. The Repo<T> has CRUD functions incorporated. Some of the View Models need to be mapped (unflattened, etc) ...
0
votes
0answers
100 views

Class design for Token, TokenType and regex constants

For use in a lexer class a have a class Token which represents a token of a specific type and its value, while the types are defined by the enum TokenType in which every token holds its own regular ...
1
vote
0answers
126 views

Correct Class Design for EAV Model

I need to design a class model to represent an EAV Model. I based my classes on this presentation ...
2
votes
2answers
434 views

Lazy loaded property signatures in business objects

Let's say I am designing business objects around a poorly optimized database that have no ability to change. I have a Person object with a ShippingAddress property. The ShippingAddress is very ...
5
votes
3answers
121 views

How to design a class to check if geometric figures collide?

I am making a basic game with geometric figures. I am trying to design now how to calculate if the figure collides with another figure in an Array List of figures (called entitiesList). I have: ...
2
votes
2answers
108 views

How to handle an aggregated list of the fields of multiple objects?

I have some objects each hold a list of variables, and a list which holds all variables of these objects, for example class A { List<Var> varList; } class B { List<A> aList; ...
4
votes
3answers
522 views

When is an object of real world a (computational) object in OOP world?

In an OOP design phase strategy, Any physical/conceptual object of a system can be modeled(considered) as computational object in your OOP designed program based on below two conditions: First ...
0
votes
0answers
101 views

Member vs free function [duplicate]

I've read similiar topics and also the following great article: http://www.gotw.ca/publications/mill02.htm I'm still not quite sure how to apply it though. Basically I have a class that is an ...
1
vote
1answer
159 views

UML diagram for attributes that can have two different types

I have been to an interview for a financial programming job, and I could not answer to one question for sure. I thought about it again, but I really cannot find a good answer. They asked me to design ...
2
votes
4answers
185 views

How wrong it is to have multiple associations between classes?

I'm modeling a college process, in which I have three classes: Student, Subject and Degree Degrees have their own subjects, students have a list of subjects they have passed, and also students should ...
0
votes
1answer
239 views

c# class generation/architecture for json rest service

I want to consume part of the Steam WebAPI, it's a simple Rest Service but it produces some complex json. I thought about using the Newtonsoft Json.Net Library generate my c# objects. Whats the best ...
15
votes
7answers
1k views

What's the idea behind naming classes with “Info” suffix, for example: “SomeClass” and “SomeClassInfo”?

I'm working in a project which deals with physical devices, and I've been confused as how to properly name some classes in this project. Considering the actual devices (sensors and receivers) are one ...
1
vote
0answers
218 views

Class Interfaces with Multiple Classes and Dependency Injection

NOTE ON QUESTION TITLE: I did not really even know how to phrase the title so if someone can edit and make it more articulate I would really appreciate it. QUESTION: Basically, what I'm trying to do ...
4
votes
2answers
2k views

Where to put a common database connection for my classes

I have several classes (Repositories) which do the task of saving/retrieving some objects in/from database; all of them need to establish a connection to one database. I thought in order to avoid ...
5
votes
1answer
556 views

Mutable with logic inside or immutable with logic outside?

I know immutable objects are preferred to mutable objects for reasoning and maintenance. But in occasions making a class immutable have some costs, let me explain it with a simple example: class ...
0
votes
1answer
210 views

How to structure programs that interact with databases? [closed]

I've just finished a book on MySQL and I'm in the infantile stages of learning to couple that with Java. I know that the technology I need to learn is called JDBC and that it essentially allows you to ...