Refers to structural definition of class unit in object-oriented languages.
Questions tagged [class-design]
1125 questions
13
votes
4 answers
Python Class vs. Module Attributes
I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level…

cmcginty
- 113,384
- 42
- 163
- 163
12
votes
7 answers
design class aggregation - stack allocation vs dynamic memory allocation
Please have a look at the two simplified examples of designing a class aggregation below.
Solution 1
Header
// need include, forward declaration is not enough
#include "door.h"
class CGarage
{
public:
CGarage(const std::string &val);
private:
…

nabulke
- 11,025
- 13
- 65
- 114
12
votes
5 answers
Create custom exception or use built-in exceptions?
Currently I'm in the process of writing a client class that utilizes DNS, Sockets, and SSL among other classes that love to throw exceptions. Other people will be implementing this class, so I was wondering what the best practice is for throwing…

krs1
- 1,125
- 7
- 16
12
votes
7 answers
When to make class and function?
I am a beginner to programming when I start to code I just start writing and solve the problem.
I write whole program in a single main function.
I don't know when to make class, and functions.
What are good books which I read to learn these…

nicky
- 3,810
- 9
- 35
- 44
12
votes
6 answers
C# Friend classes and OOP Composition
Given class A, which contains sets of raw data, and class B, which contains a re-organized version (GUI ready) of that data I would like to make the raw data in A visible in B.
Clearly the raw data in class A is contained in private members. I would…

Rire1979
- 652
- 12
- 24
12
votes
9 answers
Java: Return class (Not an instance)
Is it possible to return in a static method a class? I will explain...
I have:
public class A { public static void blah(){} }
public class B { }
I want to create a static method in B witch returns A. So you can…

Martijn Courteaux
- 67,591
- 47
- 198
- 287
12
votes
6 answers
Encapsulating an algorithm into a class
I'm wondering how (un)common it is to encapsulate an algorithm into a class? More concretely, instead of having a number of separate functions that forward common parameters between each other:
void f(int common1, int param1, int *out1);
void g(int…

zvrba
- 24,186
- 3
- 55
- 65
12
votes
5 answers
How can a singleton class use an interface?
I read at many places that singletons can use interfaces. Some how I am unable to comprehend this.

AJ.
- 2,561
- 9
- 46
- 81
12
votes
2 answers
Using Integer vs String for a "type" value (Database and class design)
I've been developing a few mobile games, in which those games fetch their data from a server-database.
I'm used to storing "type" values as an integer identifier, and an enum in the client to identify the data coming from the server.
As an…

Wintermute
- 267
- 3
- 8
12
votes
4 answers
Why singleton class should be sealed?
I want to know the why a singleton class should be sealed. If we are giving the constructor as private we can prevent the class to be derived right?.. Below i'm pasting few lines from MSDN. Please give me some color on it..
In this strategy, the…

Anish
- 872
- 5
- 21
- 42
12
votes
6 answers
Single Responsibility Principle: do all public methods in a class have to use all class dependencies?
Say I have a class that looks like the following:
internal class SomeClass
{
IDependency _someDependency;
...
internal string SomeFunctionality_MakesUseofIDependency()
{
...
}
}
And then I want to add functionality that…

jpoh
- 4,536
- 4
- 35
- 60
11
votes
4 answers
Changing the Type of a inherited property (to a inherited type)
using C# I have a class which contains among other meta information the root node of a directed graph. Let's call this the Container-Class. This container can appear in two different modes, Editor-Mode and Configurator-Mode. Depending on the mode,…

Aaginor
- 4,516
- 11
- 51
- 75
11
votes
1 answer
Class hierarchy of tokens and checking their type in the parser
I'm attempting to write a reusable parsing library (for fun).
I wrote a Lexer class which generates a sequence of Tokens. Token is a base class for a hierarchy of subclasses, each representing different token type, with its own specific properties.…

SasQ
- 14,009
- 7
- 43
- 43
11
votes
0 answers
Review my design : Tic tac toe game using OO methodology
This was asked as an interview question.
Design a tic tac toe using object oriented principles. The interviewer said he is not interested in the logic and he wants only the design. I gave the design as below but I was not completely satisfied.…

Vinoth Kumar C M
- 10,378
- 28
- 89
- 130
11
votes
3 answers
Core Data entity inheritance --> limitations?
I thought I'll post this to the community. I am using coredata, and have two entities. Both entities have a hierarchical relationship. I am noticing quite a lot of duplicated functionality now, and am wondering if I should re-structure to have a…

Yenyi
- 419
- 5
- 19