我正在开始学习C++
和object oriented design
. 将过程代码转换为面向对象代码的已知/常用技术是什么?哪些设计选择对以下代码有意义?
typedef struct
{
int sector;
int sectorPos;
}EndPosition;
typedef struct
{
int rotateAngles;
double brakingFactor;
}WheelStop;
WheelStop stops[][6] =
{
/* data removed for brevity */
};
typedef struct
{
int numImages; /* Number of images in win amount string */
int pixWidth;
int indexes[7]; /* indexes into NumberImages[] */
}WinAmountData;
typedef struct
{
int xOffset; /* pixel count offset before next digit */
std::string fileName;
//char fileName[20];
cairo_surface_t *image;
}ImageInfo;
ImageInfo NumberImages[] =
{
/* data removed for brevity */
};
enum { DOLLAR = 10, EURO, POUND, YEN };
double DegreesToRadians( double degrees )
{
return((double)((double)degrees * ( (double)M_PI/(double)180.0 )));
}
int InitImages( void )
{
/* uses NumberImages */
}
void DestroyNumberImages( void )
{
/* uses NumberImages */
}
int ParseWinAmountString( char *string, WinAmountData *amtData )
{
/* uses WinAmountData and enum */
}
gboolean rotate_cb( void *StopPos )
{
/* uses EndPosition and stops */
}
static gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
/* uses CairoImage class */
}
static void destroy (GtkWidget *window, gpointer data)
{
/* cleanup GTK stuff */
}
我已经考虑过了,我可能会看到两个类:
CWinAmount
这将包括处理要放置在“纺车”上的货币数量的数据结构和函数。CWheel
它将封装控制轮子动画机制的轮子数据结构和函数。
但我只是不确定这是否是一个好的设计。