Refers to structural definition of class unit in object-oriented languages.
Questions tagged [class-design]
1125 questions
9
votes
2 answers
What are best practices for designing JavaScript classes that represent UI objects in the DOM?
I am very familiar with JavaScript and OOP but am very unfamiliar with designing JS classes that are used for programming the UI (HTML). I have searched around a bit but have not come across any prevalent patterns.
Let's say I wanted to dynamically…

skyline3000
- 7,639
- 2
- 24
- 33
9
votes
4 answers
C# Limit creation of class instance to within namespace
I have two objects, RoomManager and Room, there will be several Rooms and one RoomManager. I want the RoomManager to be the only one allowed to create a Room object. So I'm wondering if there is a way to make the Room constructor (and the rest of…

jb.
- 9,921
- 12
- 54
- 90
9
votes
9 answers
Question About Where To Position Try And Catch statements
I've used try and catch statements as an easy way to keep my code running without things crashing (I would wrap everything in a big try). Recently, I've wanted to start using try and catch statements more correctly. Here as an example I have…

sooprise
- 22,657
- 67
- 188
- 276
9
votes
5 answers
How to execute a method in another thread?
I'm looking for a solution for this problem in C or C++.
edit: To clarify. This is on a linux system. Linux-specific solutions are absolutely fine. Cross-plaform is not a concern.
I have a service that runs in its own thread. This service is a class…

amso
- 514
- 1
- 6
- 14
9
votes
4 answers
Methods in Object-Oriented Design
Q1.
In my university studies of object-oriented modelling and design they recommend thinking about what an object can do for its method, and what its responsibilities are for its attributes. All attempts at clarification have resulted in further…

laurencer
- 1,680
- 1
- 19
- 29
9
votes
6 answers
Should I use struct or class?
I am in a classic design dilemma. I am writing a C# data structure for containing a value and measurement unit tuple (e.g. 7.0 millimeters) and I am wondering if I should use a reference type or a value type.
The benefits of a struct should be less…

Holstebroe
- 4,993
- 4
- 29
- 45
9
votes
11 answers
Should I be using inheritance?
This is more of a subjective question, so I'm going to preemptively mark it as community wiki.
Basically, I've found that in most of my code, there are many classes, many of which use each other, but few of which are directly related to each other.…

drharris
- 11,194
- 5
- 43
- 56
9
votes
6 answers
What options are there for visualising class relationships in a Python program
I am maintaining a Python program, and am struggling to understand the relationships between the various classes. I think it would be helpful to see a diagram of how the classes interact.
What options are there available that might allow me to do…

David Sykes
- 48,469
- 17
- 71
- 80
9
votes
1 answer
C++ Low latency Design: Function Dispatch v/s CRTP for Factory implementation
As part of a system design, we need to implement a factory pattern. In combination with the Factory pattern, we are also using CRTP, to provide a base set of functionality which can then be customized by the Derived classes.
Sample code below:…

Sid
- 129
- 1
- 9
9
votes
5 answers
Large Inner classes and private variables
One thing I've run into a few times is a service class (like a JBoss service) that has gotten overly large due to helper inner classes. I've yet to find a good way to break the class out. These helpers are usually threads. Here's an example:
/**…

Chris Kessel
- 5,583
- 4
- 36
- 55
9
votes
1 answer
When is a C# class with no methods poor design?
When is a class with no methods poor design?
From what I've read, a class with no methods (i.e. no behaviors) (AKA dumb class) is poor design, with the exception of Data Transfer Objects (DTOs). This is due to the purpose of DTOs being to reduce…

shansen
- 265
- 4
- 14
9
votes
2 answers
classmethod as constructor and inheritance
The problem is quite simple. If a class B inherit a class A and wants to override a ´classmethod´ that is used as a constructor (I guess you call that a "factory method"). The problem is that B.classmethod will want to reuse A.classmethod, but then…

Touki
- 833
- 2
- 9
- 20
9
votes
2 answers
what is the differences between class and dataType
As i read through UML specification that:
class has a set of attributes/operations
and data type has a set of attributes/operations
1)with regards to attributes/operations of data type
what this means?
because i don't know how such a data type has…

Andrew
- 713
- 3
- 10
- 19
9
votes
9 answers
When would you want to nest classes in C#?
Specifically, can anyone give me concrete examples of when or when not to use nested classes?
I've known about this feature since forever, but never had a reason to use it.
Thanks.

John B
- 20,062
- 35
- 120
- 170
8
votes
2 answers
Best way to make a PDO mysql static connection class?
I'm quite new to PDO and also OOP with PHP in general so please be nice :) Basically I'm trying to make a connection object based on PDO so that I can have one connection that I call throughout my site.
I need some prepared statements that simply…

Tim
- 6,986
- 8
- 38
- 57