O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.8. A Hybrid Abstract Base Class

The solution-set data member is the same for each derived-class query type: an array of integers indicating the matching lines of text. In our initial design, our Query class defines an abstract property encapsulating the solution set:

abstract public class Query
{
    abstract public int [] Solution { get; }
    // ...
}

Each derived class, in turn, defines the actual solution-set instance data member and provides the actual implementation of get for the Solution property—for example,

public class NotQuery : Query
{
   private int [] solution_set;
   virtual public int [] Solution
   {
          get{ return solution_set; }
   }
   // ...
}

Consider the following code fragment, in which parseQuery() represents a utility that transforms a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required