Results 1 to 6 of 6

Thread: [2005] Abstract/Interface/Class?

  1. #1

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    [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.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: [2005] Abstract/Interface/Class?

    Quote 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!

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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
  •  



Click Here to Expand Forum to Full Width