Refers to structural definition of class unit in object-oriented languages.
Questions tagged [class-design]
1125 questions
684
votes
20 answers
Why is __init__() always called after __new__()?
I'm just trying to streamline one of my classes and have introduced some functionality in the same style as the flyweight design pattern.
However, I'm a bit confused as to why __init__ is always called after __new__. I wasn't expecting this. Can…

Dan
- 33,953
- 24
- 61
- 87
243
votes
23 answers
How do you design object oriented projects?
I'm working on a large project (for me) which will have many classes and will need to be extensible, but I'm not sure how to plan out my program and how the classes need to interact.
I took an OOD course a few semesters back and learned a lot from…

Victor
- 5,697
- 6
- 34
- 41
212
votes
24 answers
How will I know when to create an interface?
I'm at a point in my development learning where I feel like I must learn more about interfaces.
I frequently read about them but it just seems like I cannot grasp them.
I've read examples like: Animal base class, with IAnimal interface for things…

user53885
- 3,809
- 11
- 33
- 43
190
votes
8 answers
PHP 5: const vs static
In PHP 5, what is the difference between using const and static?
When is each appropriate? And what role does public, protected and private play - if any?

Chris Jacob
- 11,878
- 7
- 47
- 42
150
votes
6 answers
How do I design a class in Python?
I've had some really awesome help on my previous questions for detecting paws and toes within a paw, but all these solutions only work for one measurement at a time.
Now I have data that consists off:
about 30 dogs;
each has 24 measurements…

Ivo Flipse
- 10,222
- 18
- 50
- 63
141
votes
10 answers
Best practice: ordering of public/protected/private within the class definition?
I am starting a new project from the ground up and want it to be clean / have good coding standards. In what order do the seasoned developers on here like to lay things out within a class?
A : 1) public methods 2) private methods 3) public vars 4)…

tempname
- 1,413
- 2
- 10
- 5
127
votes
31 answers
Is UML practical?
In college I've had numerous design and UML oriented courses, and I recognize that UML can be used to benefit a software project, especially use-case mapping, but is it really practical? I've done a few co-op work terms, and it appears that UML is…

Chris
- 6,761
- 6
- 52
- 67
115
votes
12 answers
How do I alias a class name in C#, without having to add a line of code to every file that uses the class?
I want to create an alias for a class name. The following syntax would be perfect:
public class LongClassNameOrOneThatContainsVersionsOrDomainSpecificName
{
...
}
public class MyName =…

Ian Boyd
- 246,734
- 253
- 869
- 1,219
106
votes
10 answers
What is the purpose of a marker interface?
What is the purpose of a marker interface?

coder
- 3,205
- 5
- 26
- 14
76
votes
29 answers
How do you find a needle in a haystack?
When implementing a needle search of a haystack in an object-oriented way, you essentially have three alternatives:
1. needle.find(haystack)
2. haystack.find(needle)
3. searcher.find(needle, haystack)
Which do you prefer, and why?
I know some…

Anders Sandvig
- 20,720
- 16
- 59
- 73
56
votes
3 answers
new types may not be defined in a return type - C++
I am confused I think on C++ class structure.
I have a .h called FxMathFunctions.h and a .cpp called FxMathFunctions.cpp
the .h starts like:
class FxMathFunctions
{
public:
FxMathFunctions();
~FxMathFunctions();
and in the…

jDOG
- 1,191
- 5
- 12
- 13
55
votes
9 answers
Ruby - share logger instance among module/classes
Working on a little Ruby script that goes out to the web and crawls various services. I've got a module with several classes inside:
module Crawler
class Runner
class Options
class Engine
end
I want to share one logger among all those of…

Rob Cameron
- 9,674
- 7
- 39
- 42
55
votes
2 answers
Nested Java enum definition - does declaring as static make a difference?
I have an interface - here's a nicely contrived version as an example:
public interface Particle {
enum Charge {
POSITIVE, NEGATIVE
}
Charge getCharge();
double getMass();
etc...
}
Is there any difference in how…

serg10
- 31,923
- 16
- 73
- 94
53
votes
11 answers
Class members that are objects - Pointers or not? C++
If I create a class MyClass and it has some private member say MyOtherClass, is it better to make MyOtherClass a pointer or not? What does it mean also to have it as not a pointer in terms of where it is stored in memory? Will the object be created…

Mark
- 1,538
- 5
- 24
- 31
51
votes
5 answers
no default constructor exists for class
#include "Includes.h"
enum BlowfishAlgorithm
{
ECB,
CBC,
CFB64,
OFB64,
};
class Blowfish
{
public:
struct bf_key_st
{
unsigned long P[18];
unsigned long S[1024];
};
…

Abanoub
- 3,623
- 16
- 66
- 104