3 ms·
> Your ChessBoard class should only be concerned with chess-board-ness. A separate second idea is that your program only needs one board. That’s not a fact intr
by amp108 4y ago
> Your ChessBoard class should only be concerned with chess-board-ness. A separate second idea is that your program only needs one board. That’s not a fact intrinsic to chess boards, so it shouldn’t be coded into your ChessBoard class.
This is a remarkably bad example, because either (a) a program might need more than one board (e.g., a server for multiple games), in which case the example is irrelevant, or (b) singularity really is a fact intrinsic to chess boards, and is therefore a perfect example of a Singleton.
- bluesign 4y agoI read that more like: your program needs only one board is not enough reason to make ChessBoard singleton.
- nedbat 4y agoThe point is to separate what is true about an object by its nature (what do we know about chess boards), from what is true about how we intend to use the object (we need only one of them). There's no reason to bundle those two concepts together.