Refers to structural definition of class unit in object-oriented languages.
Questions tagged [class-design]
1125 questions
26
votes
2 answers
python 3: class "template" (function that returns a parameterized class)
I am trying to create a function that is passed a parameter x and returns a new class C. C should be a subclass of a fixed base class A, with only one addition: a certain class attribute is added and is set to equal x.
In other words:
class C(A):
…

max
- 49,282
- 56
- 208
- 355
26
votes
5 answers
In C#, what is the purpose of marking a class static?
In C#, what is the purpose of marking a class static?
If I have a class that has only static methods, I can mark the class static or not. Why would I want to mark the class static? Would I ever NOT want to mark a class static, if all the methods…

Cheeso
- 189,189
- 101
- 473
- 713
25
votes
8 answers
When/why to make function private in class?
When should i make a function private and why is it good idea?

Ramilol
- 3,394
- 11
- 52
- 84
24
votes
6 answers
How can I determine whether a Delphi object is of a specific class and not any descendant class?
I have these classes and a procedure:
TParent = class(TObject);
TChild1 = class(TParent);
TChild2 = class(TParent);
Procedure DoSomething(obj:TParent);
What I would like to do is when obj is a TParent and not a descendant raise an…

Christopher Chase
- 2,840
- 6
- 36
- 57
23
votes
16 answers
Design pattern for class with upwards of 100 properties
What advice/suggestions/guidance would you provide for designing a class that has upwards of 100 properties?
Background
The class describes an invoice. An invoice can have upwards of 100 attributes describing it, i.e. date, amount, code, etc...
The…

Metro Smurf
- 37,266
- 20
- 108
- 140
23
votes
4 answers
UML class diagram: is this how to write abstract method and property?
When I was creating the first time an uml class diagram for a small C# project I had some trouble with the properties. At the end I just added the properties as a variable with <> at the start. Now Im wondering how do I solve this with an…

silla
- 1,257
- 4
- 15
- 32
22
votes
3 answers
Using nested classes for constants?
What's wrong with using nested classes to group constants?
Like so:
public static class Constants
{
public static class CategoryA
{
public const string ValueX = "CatA_X";
public const string ValueY = "CatA_Y";
}
…
user121292
22
votes
4 answers
UML Class Diagram for User Login
The diagram below is my very first attempt at creating a UML class diagram describing a user login into a website.
I'm sure its a poor design and full of flaws, but I'm hoping to learn from you guys how you would design a simple login like this.…

Anthony
- 3,990
- 23
- 68
- 94
21
votes
6 answers
What's the most reliable way to prohibit a copy constructor in C++?
Sometimes it's necessary to prohibit a copy constructor in a C++ class so that class becomes "non-copyable". Of course, operator= should be prohibited at the same time.
So far I've seen two ways to do that. Way 1 is to declare the method private and…

sharptooth
- 167,383
- 100
- 513
- 979
21
votes
7 answers
Is this bad oop design?
I have class called Chicken and in Chicken I have some methods,
so in another class where I instantiate and call methods on Chicken, I might do something like this:
Chicken chicken = new Chicken("Name","Description")
public void…

Xaisoft
- 45,655
- 87
- 279
- 432
21
votes
3 answers
Android: can I use one SQLiteOpenHelper class for multiple database files?
My app uses two databases (separate files). To handle these databases I have created two Helper classes which extend SQLiteOpenHelper, one for each database.
I am now going to add a third database and wonder whether I need to create yet another…

prepbgg
- 3,564
- 10
- 39
- 51
21
votes
6 answers
"Public" nested classes or not
Suppose I have a class 'Application'. In order to be initialised it takes certain settings in the constructor. Let's also assume that the number of settings is so many that it's compelling to place them in a class of their own.
Compare the following…

G S
- 35,511
- 22
- 84
- 118
20
votes
4 answers
Create class diagram from c++ source?
Is there any free tools available for generating class diagram from c++ source files and if possible for mfc source files too.

yesraaj
- 46,370
- 69
- 194
- 251
20
votes
2 answers
Howto design for extension
There is a Checkstyle rule DesignForExtension. It says: if you have a public/protected method which is not abstract nor final nor empty it is not "designed for extension". Read the description for this rule on the Checkstyle page for the…

Eduard Wirch
- 9,785
- 9
- 61
- 73
20
votes
5 answers
What is the logic behind having a mutable and immutable versions of classes like NSArray, NSDictionary etc in Objective C?
Why do common collection classes in Objective C like NSString, NSArray, NSDictionary etc have a mutable as well as an immutable version. What is the logic behind defining them separately? Performance, memory management or anything else?

NSExplorer
- 11,849
- 12
- 49
- 62