Chess piece hierarchy design: inheritance vs type fields

前端 未结 6 782
别跟我提以往
别跟我提以往 2021-02-15 13:23

I have a base class for pieces

 class piece;

and an array containing derived objects

piece* board[8][8];

Advantag

6条回答
  •  眼角桃花
    2021-02-15 14:21

    I would go with the hierarchy and if I want to know the type (why?) have a virtual method which identifies the type.

提交回复
热议问题