我目前正在为我的课程作业编写的应用程序设计类,我有两个类听起来好像它们应该是基派生类对,并且确实共享两个成员变量,我的问题是它们每个都有七个成员变量并且没有操作。
这些类的结构的原因是我正在构建一个 RSS 阅读器,并且我打算让这两个类保存提要上的数据。第一个将保存提要本身的数据,例如源 url、rss.xml 文件在本地存储中的位置、提要的最后更新时间等。第二个将保存有关包含在提要中的文章的信息提要,例如发布日期/时间和基于发布日期的整数索引,用于按时间顺序对文章进行排序。
class feed
{
string title;
string description;
string feed_url;
string local_location;
string channel;
bool feed_is_changed; // This is a flag that will be raised and lowered
// when the feeds are being refreshed
double last_updated; // The last update date/time will be converted to a
//standardised double value
}
class feed_item
{
string title;
string description;
double pub_time;
double pub_time_in_sec; // I'm separating the seconds so they can be used
// for a 'sub-index' when there are multiple feeds with the same pubtime
// (there are restrictions on the data types we are allowed to use
// (concocting work-arounds will aid in understanding, etc))
double pub_date;
int pub_year;
int order_in_list; // The index that will be calculated from pub_time,
// pub_date, etc
}
上面的代码不完整,我目前只识别变量和函数,私有/公共位一旦完成就会出现。从上面的代码可以看出,唯一共享的两个变量是标题和描述。
我不确定是否值得将它们设为实体基对并仅停用五个不相关的变量,是否将它们完全分开的类更有效,或者这是否完全是情境问题,并且可以争论无论哪种方式。我担心的是代码可能难以维护和扩展,但一种方法或另一种方法可能存在固有的执行开销。对此的任何想法和建议将不胜感激。