Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Interface VS Abstract classes

Interface VS Abstract classes

Scheduled Pinned Locked Moved C#
questionvisual-studio
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    seemamltn
    wrote on last edited by
    #1

    I have an nterview where I was asked What is useful to use interface or abstract classes. When We use interface and when we should use abstract classes? Thanks in advance

    seema

    P C J T 4 Replies Last reply
    0
    • S seemamltn

      I have an nterview where I was asked What is useful to use interface or abstract classes. When We use interface and when we should use abstract classes? Thanks in advance

      seema

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      And what did you say?

      1 Reply Last reply
      0
      • S seemamltn

        I have an nterview where I was asked What is useful to use interface or abstract classes. When We use interface and when we should use abstract classes? Thanks in advance

        seema

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        An interface can be used in multiple, unrelated classes ( think IDisposable ). An abstract base class allows you to store a base type, for example, whenever I write paint tools, I use an abstract base type 'Tool' class, and store an instance of it in the control that uses it, it's always a type of tool, but the base class gives me a way to store any of them. I've actually never had an interview for a company that didn't end up offering me a job. My first ever interview was the only one I failed, and I bought books and learned all I needed to go back a year later, and get a job from them. You need to move past the specific questions they asked and ask yourself what your inability to answer them tells you about broader areas in which you need to improve your knowledge.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        1 Reply Last reply
        0
        • S seemamltn

          I have an nterview where I was asked What is useful to use interface or abstract classes. When We use interface and when we should use abstract classes? Thanks in advance

          seema

          J Offline
          J Offline
          Jeff Hu
          wrote on last edited by
          #4

          The usage of interface is like a contract. That is to use it to control the entry port and the output to fit some rule that you need. And abstract class is like a context. It's containing the common attributes and deflaut behaviors those could be extented in the subclasses. When we use it is meaning how do we use interface and abstract classes. Use interfaces when something will change frequently. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent for it. It let you define some behaviors, they force your subclasses to provide others Jeff

          1 Reply Last reply
          0
          • S seemamltn

            I have an nterview where I was asked What is useful to use interface or abstract classes. When We use interface and when we should use abstract classes? Thanks in advance

            seema

            T Offline
            T Offline
            tker
            wrote on last edited by
            #5

            Hi Seema, Interfaces are essential when programming using Component Orientated Design as opposed to OOD. In general I tend towards using Interface inheritance as I code for components, not objects. Components are more flexible and reusable, in no small part due to the way they interact using Interfaces and thus separate interface from implementation, making reimplementation or reuse easier. Interface based inheritance means simplifies greatly the use of inheritance and polymorphism as abstract classes may implement member variables or provide virtual functions as well as abstract functions which can make the hierarchy more fragile and prone to reuse issues. If you need common functionality across a number of subclasses then an abstract class is useful; it is, however, also useful to make that abstract class implement an interface for its subclasses to use as their contract with their clients as well. A class may only implement one base class, but can implement multiple interfaces. If an interface implements another interfaces then classes that implement that interface will have to implement the methods for both. Conflicts may be resolved via explicit interface inference or by channeling both into one method (or a combination). As with abstract classes, interfaces may be Generic and decorated with attributes. Interfaces are a very useful and powerful construct. I would recommend their use heavily to achieve a component based architecture rather than an object based architecture. Toby Toby Russell

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups