Questions tagged [object-design]
22 questions
59
votes
3 answers
std::mutex vs std::recursive_mutex as class member
I have seen some people hate on recursive_mutex:
http://www.zaval.org/resources/library/butenhof1.html
But when thinking about how to implement a class that is thread safe (mutex protected), it seems to me excruciatingly hard to prove that every…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
8
votes
2 answers
@property speed overhead in Python
I'm trying to understand the utility of the @property decorator in Python. Specifically, I set up a class using properties like so:
class A(object):
def __init__(self, x):
self._x = x
@property
def x(self):
return…

paul
- 101
- 1
- 5
5
votes
4 answers
Is passing(in constructor) a pointer to class that contains it a bad design and if so what is the solution
often I encounter code like
/*initializer list of some class*/:m_member(some_param,/* --> */ *this)
Reason why this is done is so that m_member can call member functions from the class that contains it...
aka
//code in class that is m_member…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
5
votes
1 answer
How to avoid name clashes when composing objects
In JavaScript you can compose objects using some kind of extend function.
For example I might have an observable class that exposes a set of public methods (get, push, set, increment, get, etc)
In this case the observable also happens to be an…

Raynos
- 166,823
- 56
- 351
- 396
4
votes
3 answers
Model a database foreign key in c#
I am creating a calendar application. I have a Appointment table, and a Person table. The 2 are linked by PersonID field in each table.
My question is, should my underlying .Net Appointment object contain a property for the PersonName, and I…

MillinMo
- 395
- 1
- 7
- 21
4
votes
3 answers
Justification for the design of the public interface of ByteArrayOutputStream?
There are many java standard and 3rd party libraries that in their public API, there are methods for writing to or reading from Stream.
One example is javax.imageio.ImageIO.write() that takes OutputStream to write the content of a processed image to…

Op De Cirkel
- 28,647
- 6
- 40
- 53
4
votes
2 answers
Redundant code in composition class C++
I'm trying to pick up C++. Everything was going well until my 'practice' program hit I very minor snag. That snag, I believe, stems from a design issue.
Think of Blackjack(21). I made a few classes.
Card
Deck
Hand
Player
A Deck consists of -…

Aaron P
- 43
- 5
3
votes
4 answers
PHP OOP Question
Is it possible to require objects in PHP 5.3 to contain certain constants or properties? I read a bit on PHP's interface model and it seems it only works for abstract public methods so that's right out. So what i'm asking is if there is a way to…

chrisw
- 407
- 4
- 12
3
votes
4 answers
Object Design: How to Organize/Structure a "Collection Class"
I'm currently struggling to understand how I should organize/structure a class which I have already created. The class does the following:
As its input in the constructor, it takes a collection of logs
In the constructor it validates and filters…

CrimsonX
- 9,048
- 9
- 41
- 52
2
votes
8 answers
Is a static class appropriate when state is immutable?
Let's say I have a simple class called WebsterDictionary that has a function that can take a word and return its definition. Perhaps there is another function that can take a definition and return a word. The class is used all the time by many…

Rob Sobers
- 20,737
- 24
- 82
- 111
2
votes
2 answers
How to create nested generator structures in python?
I'm trying to create an ImageSeries object, where I want to retrieve images in a certain pattern (for every value in xy, and every value in z), and I call methods that will append a generator to a tasks list, and run the generator through two for…

pskeshu
- 199
- 1
- 9
2
votes
4 answers
Advice on Linq to SQL mapping object design
I hope the title and following text are clear, I'm not very familiar with the correct terms so please correct me if I get anything wrong. I'm using Linq ORM for the first time and am wondering how to address the following.
Say I have two DB…

fearofawhackplanet
- 52,166
- 53
- 160
- 253
2
votes
1 answer
Making decisions on designing classes interfaces
I would like to get some thoughts from others about the following problem.
Let's assume we have two classes Products and Items. Products object allows us to access any Item object. Here's the example.
$products = new Products();
// get existing…

marcin_koss
- 5,763
- 10
- 46
- 65
1
vote
4 answers
C# class design with Generic structure
This might be a simple one, but my head is refusing to wrap around that, so an outside view is always useful in that case!
I need to design an object hierarchy to implement a Parameter Registration for a patient. This will take place on a certain…

Sam
- 1,514
- 2
- 14
- 22
1
vote
1 answer
TDD And CodeFirst (Entity Framework)
This question is not about how to test the data access, nor the repository. It's about the problem i have when i want to use my POCO classes (that i've made with TDD) in the project.
I mean, this is the problem because of the Linq to Entities…

ascherman
- 1,762
- 2
- 20
- 41