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 ...
Get C# Primer: A Practical Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.