|
-
Oct 4th, 2006, 03:51 PM
#1
Thread Starter
Frenzied Member
[2005] Abstract/Interface/Class?
I need a bit of guidance on the way to implement my project.
I am going to communicate with several manufacturers of an instrument e.g. an LCD Monitor.
Each has the same functions e.g. On/Off, Brightness, Position etc etc
However, the commands for each manufacturer to do these functions is different.
I'm not sure whether I should have a Monitor interface then have other classes that implement the interface, or whether to have an abstract class and inherit that.
-
Oct 4th, 2006, 03:57 PM
#2
Re: [2005] Abstract/Interface/Class?
Depends how much they have in common. If they are very varied, then use an interface. If they share a lot of common code with some specialisations, then use an abstract class.
-
Oct 4th, 2006, 05:12 PM
#3
Re: [2005] Abstract/Interface/Class?
The relationship between a class and an interface is the same between itself and it's parent class. But I'd go with the super class, because I don't think it'll do any good to your classes just inheriting the Object class.
And for the code that penagate mentioned, it doesn't matter. If it's shared write it in the super otherwise give it a name and make it abstract (Must be overridden in each and all sub classes)
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 4th, 2006, 05:20 PM
#4
Re: [2005] Abstract/Interface/Class?
Think of it this way: a base class is something that a class IS, while an interface is a role that a class can fill. In the real world you have the Printer class. You cannot create a Printer object without it being a specific type of printer, so Printer is an abstract class. Now many printers provide a USB interface, but then so do scanners, digital cameras and God knows how many other incredibly varied peripherals. They don't inherit the Printer class but they all provide a USB interface, so they can all be plugged into a computer's USB port. Remember that OOP has been designed to mimic real life.
-
Oct 4th, 2006, 05:51 PM
#5
Banned
Re: [2005] Abstract/Interface/Class?
 Originally Posted by jmcilhinney
Think of it this way: a base class is something that a class IS, while an interface is a role that a class can fill. In the real world you have the Printer class. You cannot create a Printer object without it being a specific type of printer, so Printer is an abstract class. Now many printers provide a USB interface, but then so do scanners, digital cameras and God knows how many other incredibly varied peripherals. They don't inherit the Printer class but they all provide a USB interface, so they can all be plugged into a computer's USB port. Remember that OOP has been designed to mimic real life.
I'm not one to judge, but every time I read jmcilhinney's responses I feel like I've learned to look at something in a different perspective. I'm fully aware of how OOP, and I definately know when or when not to interface, inherit, polymorph and all those cool buzz words . However, I think when jmcilhinney (God i wish I knew your first name cause typing that is not fun) explains something it has a great meaning. To that I say GREAT EXPLANATION!
-
Oct 4th, 2006, 06:45 PM
#6
Re: [2005] Abstract/Interface/Class?
I agree that typing JMs name is not fun, however, I found a way around it
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|