Author: Alexander Kure
Date: 05:44:09 01/06/06
Go up one level in this thread
On January 06, 2006 at 03:37:17, Gerd Isenberg wrote: [..] >>3) Instead of low-levely maipulating a square by means of operator+=() you could >>declare the following high-level functions in class CSquare: >> >> void Up(); >> void Down(); >> void Left(); >> void Right(); >> void Next(); >> void Previous(); > >Isn't it better to return a reference for this functions, to cascade several >directions in one expression? If you like to cacsacde these functions then your suggestion of returning a reference for these functions is the way to do it. > What about throwing an out of board exception? Good idea but depends on how these functions should behave. You could for example let them wrap around the board. >>4) You could also declare other convenient functions outside of class CSquare: >> >> bool IsAdjacent(const CSquare&, const CSquare&); > >while polymorphism is a nice thing to have, this function may also be member of >CSquare. I don't understand what polymorphism has to do with it but concerning your question if this function may also be member of CSquare: From the perspective of encapsulation - an important issue in OO - it is better to define IsAdjacent() as a non-member non-friend function in order to increase encapsulation. The idea is to separate the implementation issues of IsAdjacent() from the internals (read: non-public interface, i.e. protected and private interface) of CSquare by just using its public interface only - thus increasing encapsulation. If this can be done without a serious performance penalty this is surely the way to do it. Since IsAdjacent() can be implemented by using CSquare::GetFile() and CSquare::GetRank() that are both inlined member functions there is no performance penalty at all. A change of the internals of CSquare later in the development process does not effect (read: need to be changed) non-member functions like IsAdjacent() that rely on the public interface of CSquare only. In contrast all member functions of CSquare dependant on the internals are effected and need to be changed. Best, Alex
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.