Thread: Abstract or Interface?

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Abstract or Interface?

    Anyone know what are abstract classes and interfaces?

    Not as language construct but conceptually.



    In object oriented design matters, we should separate multiple responsibilities classes.

    But how do we connect them?
    Should we use abstract classes or interfaces?

    Why do we use abstract class?
    Why do we use interface?

    Anyone know please?
    Thanks in advance.
    Just GET it OFF out my mind!!

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    An abstract class is generally an interface in C++.
    It's good to use abstract classes since they often contain common functionality used by several classes. There is also no sense in being able to create an abstract class, which is why it is marked abstract, thus becoming an interface, something you cannot create an instance of, only derive from.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Actually abstract classes == interface isn't it?

    Why do so much language separating "abstract class" and "interface" ?
    Just GET it OFF out my mind!!

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What I can say for sure is that it's called an abstract class in the language, but an interface conceptually.
    So you really call them whichever.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    They are called an Interface because these classes main objective is to define a protocol, or a set of rules for other classes deriving from it to use. The abstract class itself is not meant to be instantiated.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    An abstract class can define some of it's member functions, but as long as it has at least one pure virtual function (without being defined) then it's an abstract class; an interface has all pure virtual functions (no functions are defined).

    In Java they make the distinction easier by having separate 'abstract' & 'interface' keywords.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Google brings up some results.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Abstract inheritence
    By Chris87 in forum C++ Programming
    Replies: 6
    Last Post: 06-18-2009, 10:47 AM
  2. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  3. Calling IRichEditOle interface methods
    By Niara in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 01:23 PM
  4. abstract class
    By xddxogm3 in forum C++ Programming
    Replies: 5
    Last Post: 01-01-2005, 09:08 AM
  5. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 01:12 PM