dcsimg
Results 1 to 4 of 4

Thread: What is the purpose of an Abstract Class and is it used much?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,865

    What is the purpose of an Abstract Class and is it used much?

    I'm trying to visualize an abstract class in code examples and it's just not clicking. What are they exactly? Are they used much? What is the difference between them and a regular class?

    Thanks,
    Blake

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,641

    Re: What is the purpose of an Abstract Class and is it used much?

    The 'abstract' keyword in C# is equivalent to MustInherit (class) and MustOverride (member) in VB. An abstract class is sort somewhere between an interface and a "regular" base class. In the case of an interface, you declare members that any class that implements it must have but you provide no implementation for any of them, so a class that implements that interface has to provide an implementation for each member. In the case of a base class, you declare members that any class that inherits it must have and you provide an implementation for all of them, so a class that inherits that base class doesn't have to provide any implementation at all, but it can if it wishes to override an existing implementation.

    In the case of an abstract class, you declare members that any class that inherits it must have but you can decide whether to provide an implementation for each of those members or not. Any that you do not provide an implementation for must be declared 'abstract' too and then and derived class must override those members and provide its own implementation. Abstract classes don't get used all that much but as I said, they pretty much combine the functionality of an interface and a base class so you would use one when that's what you want, i.e. to specify all the interface and some of the implementation.
    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

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,641

    Re: What is the purpose of an Abstract Class and is it used much?

    An example of an abstract class is System.IO.Stream. Any type of stream (FileStream, MemoryStream, NetworkStream, CryptoStream) inherits from the Stream class but they all provide much of their own implementation because they all work with very different data sources, but there's also some commonality to the implementation in the base class.
    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

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,865

    Re: What is the purpose of an Abstract Class and is it used much?

    That seems like a great explanation but I need to wrap my head around it still. Thanks JMC.
    Blake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width