General guidelines on how to design classes with best known industry practices.
2
votes
3answers
520 views
GUI: Setting options in two different places and having them stay in sync?
Programming in Windows with Visual Studio 2010 C++ and MFC. My question is about how best to store, update, and pass around program settings or options.
I have a simple main GUI window/frame/dialog. ...
3
votes
2answers
251 views
How to deal with pointers from child to parent?
I have a class that represents a file in specific binary format on disk (the parent in the title) and another class that represents an object inside that file (child). When the object changes, it ...
4
votes
6answers
256 views
Fields vs method arguments [on hold]
I just started writing some new class and it occurred to me that I was adding a lot of method arguments that are not strictly needed. This is following a habit to avoid having state in classes that is ...
0
votes
1answer
67 views
Class Design for special business rules
I'm developing an application that allows people to place custom manufacturing orders. However, while most require similar paperwork, some of them have custom paperwork that only they require. My ...
3
votes
3answers
325 views
Architecting persistence (and other internal systems). Interfaces, composition, pure inheritance or centralization?
Suppose that you need to implement persistence, I think that you're generally limited to four options (correct me if I'm wrong, please)
Each persistant class:
Should implement an interface ...
19
votes
2answers
1k views
Is it a good idea to provide different function signatures that do the same thing?
Here is a C++ class that gets constructed with three values.
class Foo{
//Constructor
Foo(std::string, int, char);
private:
std::string foo;
char bar;
int baz;
};
All of ...
0
votes
1answer
154 views
Code design: is this specific case of monkeypatching in python acceptable?
I'm using python to do some research tasks. I have a class hierarchy for "tools", where each object is an instance of a particular tool. They all share some functionality and have many similarities in ...
0
votes
2answers
138 views
Is it valid to initialize an instance of a class within the same class?
I was wondering if it's valid to initialize an instance of a class within the same class? For example:
public class Person()
{
string name;
string age;
public Person getPerson()
{
...
0
votes
3answers
221 views
Have Superclass Contain List of Subclass?
For the GUI of a program, I want it to list several items, all of which are, from a programming side, just subclasses. They can add one of these items to a list. I don't want to hard-code which ...
0
votes
3answers
256 views
What is good practice when inheriting static classes isn't possible/allowed
I am developing a project in C# and due to a design decision it is not possible to have a static class inherit another static class. But I have, in my opinion, a case where this would make sense.
I ...
2
votes
5answers
538 views
Why is TDD not working here?
I want to write a class A that has a method calculate(<params>). That method should calculate a value using database data. So I wrote a class Test_A for unit testing (TDD). The database access ...
1
vote
1answer
126 views
Is it evil to model JSON responses to classes when they are mostly smilar?
Here's the problem :
While implementing a C# wrapper for an online API (Discogs) I've been faced to a dilemma : quite often the responses returned have mostly similar members and while modeling these ...
0
votes
3answers
134 views
which style of member-access is preferable [duplicate]
the purpose of oop using classes is to encapsulate members from the outer space. i always read that accessing members should be done by methods. for example:
template<typename T>
class foo_1 {
...
0
votes
1answer
100 views
Refactoring classes with ref to themselves
How can I refactor this code?
class Node
{
public Node Parent { get; set; }
}
class AVLNode
{
public AVLNode Parent { get; set; }
}
I tried to use inheritance, but then I have to use type ...
2
votes
2answers
190 views
When to use inheritance or composition/aggregation?
In general, how do I decide whether to use make a class a super class, or to make it a private data member of another class? For example, given two classes, how does one decide whether to do this:
...