4.3. Defining an Interface
In Section 4.1 we implemented a new instance of an existing interface. In Section 4.2 we simply discovered and used the interface associated with a given type. In this section we introduce an interface definition. This interface supports the generation and display of sequences of numbers based on a unique algorithm. Here is the general set of operations we wish to support (two methods, a property, and an indexer):
GenerateSequence(), which generates the unique sequence of elements
Display(), which outputs the elements
Length, which returns a count of the number of elements
Indexer, which allows the user to access a specific element
An interface definition begins with the keyword interface followed by a name. Recall that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access