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

learn more… | top users | synonyms

0
votes
0answers
29 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
77 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
26 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
56 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
195 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
32 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
176 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, ...
13
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 ...
88
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
176 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 ...
7
votes
2answers
420 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
199 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
692 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
2answers
301 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
2answers
120 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
45 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
136 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
223 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 ...
1
vote
1answer
57 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 ...
1
vote
2answers
35 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
107 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
188 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 ...
2
votes
2answers
150 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
113 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
147 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
105 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
95 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
113 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
249 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
231 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 && ...
1
vote
2answers
97 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
210 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
506 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
159 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 options....
14
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
67 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
169 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
91 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
61 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. ...
1
vote
2answers
205 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
1k 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
236 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
142 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
280 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 ...
1
vote
0answers
28 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
164 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
172 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 http://www.slideshare.net/stepanyuk/implementation-of-eav-pattern-for-activerecord-models-13263311?...
2
votes
2answers
757 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
138 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
118 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; ...