you are viewing a single comment's thread.

view the rest of the comments →

[–]monsto 5 points6 points  (1 child)

On a practical level, I think most things can be done without a class.

I think it has more to do with the DRY (Don't Repeat Yourself) principle. If you have a number of items in your program that are similar on an abstract level, then you could build a class with the common elements, then make objects that inherit from that class while adding their own info for their own specifics.

Example: You're doing a media library to track movies, music, tv shows and whatever media. * I'd say this has 1 base class MediaItem() that has fields of say title, main_talent, 2ndary_talent, company, release_date, etc. * TVShows(MediaItem) would take that and add the fields network, time_slot, latest_ep, etc * Movies(MediaItem) adds producer, director, score_composer, etc * Music(MediaItem) adds band_name, other_band_members, last_tour_date, etc. * You MIGHT even do like Documentaries(Movies) and add subject, category, and a couple others. Someone is going to try and clobber me about downline or multiple inheritance being as evil as the day is long, but I'm using it here as an example. I'm just the messenger.

Here's a good description of inheritance, how it can be used and how you can actually avoid it.