Re: General rule for constructors
Daniel Pitts wrote:
So, the best advice that I can give you on this subject is borrowed from
a book (I believe Effective C++):
"Make your classes easy to use correctly, and difficult to use
incorrectly."
Also, once you think you have correctly outlined how you class should
work, check out some Design Patterns and see if they do something
markedly different. There are patterns for code too, not just design.
Best ways to implement something, and all that.
I think your original statement is good as a general rule. You should
make everything private by default, and then see what you absolutely
have to make public. Don't forget about things like Facades and
Proxies, which can help you hide the real object that does the work.
However, there will also be some specific patterns for what you are
doing, and also some anti-patterns too. Try to find the most specific
ones and apply those. Too much generalization isn't good either.
Time and familiarity will help you find the best patterns quickly. I'm
definitely still learning here too. And mis-designed code that is
nevertheless designed clearly and with forethought shouldn't be that
hard to refactor if you later decide the use of a particular pattern
wasn't the best. "Build one to throw away."