General guidelines on how to design classes with best known industry practices.
0
votes
0answers
82 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
31 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
154 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
57 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 ...
0
votes
0answers
42 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 ...
3
votes
2answers
238 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
357 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
102 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
200 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
200 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
204 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
184 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
74 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
110 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
128 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
79 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
243 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
87 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
82 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
195 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
591 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
144 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
118 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
191 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
435 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
296 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
409 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
119 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
83 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
216 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
725 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
47 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
262 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
77 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
192 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
84 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
{
...
-1
votes
1answer
238 views
Is class with callbacks a code smell in JavaScript? [closed]
When writing JavaScript (especially in node.js), I tend to use plain functions and callbacks. However, sometimes there's some context to share between some functions and I don't like to pass this ...
0
votes
1answer
236 views
When should a class be final? [duplicate]
I've only really seen this on Java's wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class ...
2
votes
4answers
525 views
When should something be a class? And are my chosen classes good OO design?
My background:
I am new to programming. Python is my only programming knowledge. I program as a hobby, and I'm teaching myself by reading copious amounts of books.
I understand enough about OOP to ...
0
votes
1answer
98 views
How to split a Service class in two but still use them like one?
I've got a class:
AuthenticationService
findLoggedInUser()
Checks session if User is logged in. If not, check client persistent user login cookie and log in.
loginUser($email, $pw, $remember = ...
2
votes
4answers
854 views
c++ coding practice class vs. “free” functions
I am currently writing my first bigger project in c++. Its basic linear algebra. I am aware that boost libraries and others exist, but for various reasons I need to write my own. Purpose of the ...
-1
votes
2answers
154 views
Class hierarchy question - do you implement separate classes for the same behavior? [closed]
NOTE: The language I am using is C#.
I am currently working on a 'The Quest' mingame where there is a player and some enemies.
My design so far involves a base abstract class called 'Mover' and an ...
4
votes
2answers
301 views
dealing with a very large state machine in a class
I am currently implementing a class for a network protocol. The protocol uses a quite complex and extensive finite state machine. A pair of an event plus a state is mapped to a function, which does ...
-3
votes
2answers
215 views
Why friend in C++ should be in the header file? [closed]
Friend function/class, FriendOfX for some arbitrary class X is an implementation detail of class X. Why in C++ we have to declare them in the header file? Are there any compelling reasons to make this ...
2
votes
1answer
130 views
class hierarchy with structurally different subclasses
I want to implement a protocol layer which sits on top of the TCP/IP stack. There is a limited set of PDUs that can be sent and for each PDU there is a class which represents it in a structured form. ...