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

learn more… | top users | synonyms

0
votes
2answers
184 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
10 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
35 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
53 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
98 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
77 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
79 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
440 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 ...
0
votes
1answer
49 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
161 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
94 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
127 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
383 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
400 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
117 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 ...
2
votes
2answers
217 views

Designing entities that should be mutable through the GUI but protected from programmer error

I have a set of entities, for now represented by very simple classes (further simplified for this example): public class Item { public string Name { get; private set; } public double ...
2
votes
4answers
202 views

When should I mix functions with data in a class?

Based on some questions I asked (1, 2,3), I am frequently suggested to separate data from functions (because of changes in function, single responsibility, separation of concerns, adopting interfaces, ...
0
votes
4answers
219 views

Fixing class Hierarchy design mistakes due to incorrect inheritance

I have a code like this. My derived class man, may not properly have a member function declared pure virtual higher up the hierarchy. eg. WagTail here class mammal{ public: virtual void WagTail() ...
0
votes
0answers
58 views

Should I ever reset object state?

I have a series of TextBlocks which are drawn on frames to make a video of a book. I do it when user click on Make Video. User may change the content of some blocks and click again on Make Video. I ...
2
votes
2answers
217 views

Abstract classes and constants

I have two classes that share a lot of code and are conceptually variations on a common class. So I want an abstract class that contains all their common code and then they can each inherit from it ...
0
votes
1answer
83 views

Is there a name for classes that only contain variables (and getters and setters)? [closed]

For example public class Student { private int id; private String firstName; private String lastName; /*getters, setters, constructors*/ } As opposed to public class Course { ...
0
votes
2answers
115 views

Distinguishing Classes: How to catch system behavior in classes (Library System Case)

Suppose a Library System. if I think about Data, I can just distinguish Book, Member classes or at most Author or Publisher... (Are they only classes?), but I have some use cases, scenarios (Borrow, ...
0
votes
2answers
134 views

Object oriented Classes and single responsibility [duplicate]

I'm reading a book that explain that it is a good thing that classes have a single responsibility, that is, that they do a single thing. I can understand how to implement this in some cases I ...
1
vote
2answers
82 views

How to organize code which converts from one type to another

If I have a DateRange class, and I want to translate a DateRange into SQL (e.g. some_col >= '2015-3-5' AND some_col <= '2015-3-5'), where should I put the method that does the translating? ...
5
votes
3answers
257 views

OOP Practice: how to best handle dependent dependencies

I have a problem with the design shown in the picture. My Section class has some TextBlocks (or simply Blocks). The section should be drawn on a page (a Bitmap as device context). It sets the blocks ...
1
vote
2answers
96 views

Literal strings vs. object properties in JavaScript

JavaScript libraries in the same space (UI widgets) use two different approaches for instantiating components: Literal strings to specify types, and inlining as much as possible, for example: var ...
0
votes
3answers
83 views

Heuristics on when should one subclass and when not [closed]

Are there any good tips, when one should subclass and when should not? It's clear that we should not subclass when we want to reuse a single method of some class we override all methods, changing ...
1
vote
1answer
196 views

Adding a graphical view to a system

I currently have an program in Java that simulates railway movements. Essentially, trains arrive on platforms, pick up and drop off passengers, and then proceed, respecting signalling where possible. ...
12
votes
2answers
614 views

Taming the 'utility functions' classes

In our Java codebase I keep seeing the following pattern: /** This is a stateless utility class that groups useful foo-related operations, often with side effects. */ public class FooUtil { ...
0
votes
2answers
157 views

Flexible and easy to use settings class

I am thinking about a way to create a flexible "settings class" in C#. The question is: How to provide a confortable way to provide default values to the settings. I want the programmer to access the ...
0
votes
3answers
123 views

where should put showSchedule method in school system

In my school management system I have this partial class diagram: 1- In one use case student want to see his schedule of classes in week. this is what i suppose to do: get student object from ...
1
vote
1answer
220 views

Does dynamically generating classes in python affect readability/performance?

I have a set of classes that represent different objects (tables in a database): class ObjA: # some class specific attributes and methods def refresh(self): # implementation ...
1
vote
2answers
483 views

many to many relation in database schema and oop class diagram

I have Student and Group entities. Student can have many groups and Group can have many students too. so in database I should have middle class and change many-to-many relation to one-to-many and ...
5
votes
2answers
317 views

Should I use events or abstract methods?

Lets say I create an abstract class that manages some network functionality for me. I want to be able to be notified when something changes. For example: OnConnect or OnDisconnect. Should I create ...
2
votes
3answers
415 views

Class design - should methods call other methods?

I'm writing a very basic custom class for coupons and I've come up with a basic layout for the class, which consists of a number of small methods as I generally understand is a best practice. What ...
0
votes
1answer
121 views

Should I use a class as a wrapper?

Lets say I have a class representing a chemical compound class Compound(networkx.Graph): def __init__(self): super(Compound, self).__init__() And lets say that I want to add some ...
0
votes
2answers
91 views

My class diagram needs to model a relationship with varying quantities

I am trying to design a restaurant ordering system in UML, which should also include the stock system. One of the classes is a Dish (i.e. a dish on the menu), and another is an Ingredient. My ...
2
votes
2answers
230 views

Passing by value multiple times vs. Creating a public class variable

Suppose I have a series of methods across different classes that all use the same five core variables defined in my main method. I could chain these five variables as method arguments from one method ...
0
votes
3answers
815 views

Force Derived Class to Implement Static Method C#

So the situation is like, I have few classes, all of which have a standard CRUD methods but static. I want to create a base class which will be inherited so that it can force to implement this CRUD ...
-2
votes
1answer
52 views

How name class which display data? [closed]

Houston, we have a problem. I can't think of a simple class name. I have abstract class, something like that: public abstract class DataDisplay { public abstract void dataDisplay(Data data); } ...
51
votes
6answers
6k views

Should a getter throw an exception if its object has invalid state?

I often run into this problem, especially in Java, even if I think it's a general OOP issue. That is: raising an exception reveals a design problem. Suppose that I have a class that has a String name ...
3
votes
1answer
283 views

How to store a potentially large amount of optional properties of objects?

I'm using Entity Framework Code First with ASP.NET MVC. This handles my database design based on the domain models within my application. As it stands, the engine I'm writing will have a website ...
0
votes
1answer
85 views

Storing Form Data in a class

I have a form that writes to a database. Other than creating a class handle an external API, this project is done. However, the processing script is your standard procedural calling of queries using ...
2
votes
2answers
194 views

Design - Parser.hasInfo(MyClass) vs MyClass.hasInfo()

I'm working on a document processing system. I feel confident with a Document class which represents each document being processed. The issue: Each Document can have a CoverSheet, and if it does, ...
0
votes
2answers
89 views

How to improve code that has to handle list-objects in general and special cases?

I do have an implementation issue that I condensed to the following code snippet, because the real code is much more complicated. The core problem is that I do have a container object that has a mixed ...
0
votes
3answers
94 views

Should foreign keys be represented directly when mapping database tables to classes? [closed]

Ok, in my database I have a table Event and a table Room. Each Room can have many Event. Room table roomID-roomName 1 - cafe102 ... Event table eventID- Time -type -roomID 1 - 11:20 - 1 ...
36
votes
9answers
5k views

Is creating subclasses for specific instances a bad practice?

Consider the following design public class Person { public virtual string Name { get; } public Person (string name) { this.Name = name; } } public class Karl : Person { ...