我目前正在爲我的課程作業編寫一個應用程序的類,並且我有兩個類,聽起來好像它們應該是基類派生的類對,並確實共享兩個成員變量,並且我的問題是他們每個人有七個成員變量,沒有任何操作。是否應該在基類和派生類之間共享特定比例的成員?
這些類的結構的原因是我正在構建一個RSS閱讀器,我打算讓這兩個類在feed上保存數據。第一個將在Feed本身保存數據,例如源URL,本地存儲中rss.xml文件的位置,上次更新Feed時的位置等。第二個將保存關於包含在諸如發佈日期/時間的饋送和基於將用於按時間順序排序文章的發佈日期的整數索引。
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
}
上面的代碼是不完整的,我目前只能識別變量和函數,以及私有/公共位會一旦他們完成。從上面的代碼可以看出,共享的唯一兩個變量是標題和的說明。
我不確定是否值得讓它們成爲一個實體 - 基礎對並且僅僅停用五個不相關的變量,如果將它們變成完全獨立的類更有效率,或者這完全是一個情境問題,並且它可以用任何方式來論證。我擔心的是代碼可能難以維護和擴展,但是可能會在一種方法或另一種方法中存在固有的執行開銷。任何想法和建議,將不勝感激。
定義'價值'和'高效'。你在優化什麼? – 2010-11-05 22:05:25
我可以問一個有7個成員變量而沒有操作的類的目的是什麼? – 2010-11-05 22:06:35
@Paul Hankin當我說'值得'和'高效'時,我正在談論代碼的可維護性和可伸縮性,以及執行效率。對不起,我應該在問題中指定。 – 2010-11-05 22:56:34