Should a specific proportion of members be shared between base and derived classes?

I'm currently designing the classes for an application I'm writing for my coursework, and I have two classes that sound as if they should be a base-derived class pair, and do indeed share two member variables, and my problem is that they each have seven member variables and no operations.

The reason for the structure of these classes is that I am building a RSS reader and I intend to have these two classes hold data on the feeds. The first one will hold the data on the feed itself, for example the source url, the location of the rss.xml file on local storage, when the feed was last updated, etc. The second will hold information on the articles contained within the feed such as the publication date/time and an integer index based on the publication date that will be used to chronologically sort the articles.

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
}

The above code is not complete, I'm currently only identifying variables and functions, and the private/public bits will come once they're finalised. As you can see from the above code, the only two variables that are being shared are title and description.

I'm not sure if it's worth making them an entity-base pair and just deactivating the five irrelevant variables, if it's more efficient to just make them completely separate classes, or if this is an entirely situational concern, and that it can be argued either way. My concerns are that the code may become difficult to both maintain and scale, but that there may be execution overhead inherent in one method or the other. Any thoughts and advice on this would be most appreciated.

Answers


A feed_item isn't a feed, so it fails the Liskov substitution principle and shouldn't be a subclass. I should check your ears — this pair of classes absolutely doesn't sound like they should be subclasses.

Occasionally (very, very occasionally) implementation inheritance is a good idea, but it's usually better done by extracting shared parts into a separate class and using it in both implementations. Here, it's absolutely a terrible idea — there's no great sharing of code, so the benefits are at best vague. Keep your code simple!


Need Your Help

Split a string at “;” with php

php string split preg-split

I have a string called $gallery, $gallery is a list of image URLS The image urls are seperated by a semi- colon ;. Example

Label widget problems

python python-2.7 user-interface tkinter tk

I am having problems in my Tkinter project. I am trying to create a simple addition calculator that only computes two numbers and. I am having trouble creating the addition function. I want to crea...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.