Diary 29th February

Today I worked on my tic tac toe application. I starter with wanting to test my Game class but then discovered that I had not implemented a move method in the board class.

Delegation everywhere

Although the game class itself has a play move method, however it delegates the responsibility to the board class.

I imagine that the Game class will delegate a lot of it’s operations, such as view related methods, boards. It’s almost just a delation class that’s glueing objects together. Perhaps it’s structure much change in the future as the design changes.

Mutable or immutable

I spent maybe 1hr trying a immutable approach of the implementation but found that perhaps I hadn’t properly grasped the concept of mutability, so instead in the current implementation the board is mutable.

Who’s responsibility is it anyways?

Spending some time with the board class raised further questions. Questions such as, what happens when a client enters an invalid move, such as passing in 10, when there’s only 9 available positions on a 3×3 board.
Another problematic scenario is when a space is already occupied. Should the playMove method return a false boolean or should it throw an exception?

It depends on whether I see it an exceptional circumstance if a client passes a position that’s already taken. Either case I’m requiring the client to handle the case on their end, whether it is by catching the exception or handling the false bool value.

I decided on throwing an exception as I wanted the client to take responsibility and handle the exception. The client should know whether it wants to play a different move or do something else. The choice should be theirs, what’s important is that they’re notified. With a bool value it’s not as clear I feel.

In the end it’s about being more conscious about each decision we make, being aware of the trade offs.

 

Ced

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s