Exercise 13-1. Define an interface IConvertible
that indicates that the class can convert a block of code to C# or VB. The interface should have two methods: ConvertToCSharp
and ConvertToVB
. Each method should take a string and return a string.
Exercise 13-2. Implement that interface and test it by creating a class ProgramHelper
that implements IConvertible
. You don’t have to write methods to convert the string; just use simple string messages to simulate the conversion. Test your new class with a string of fake code to make sure it works.
Exercise 13-3. Extend the IConvertible
interface by creating a new interface, ICodeChecker
. The new interface should implement one new method, CodeCheckSyntax
, which takes two strings: the string to check and the language to use. The method should return a bool
. Revise the ProgramHelper
class from Exercise 13-2 to use the new interface.
Exercise 13-4. Demonstrate the use of is
and as
. Create a new class, ProgramConverter
, which implements IConvertible
. ProgramConverter
should implement the ConvertToCSharp( )
and ConvertToVB( )
methods. Revise ProgramHelper
so that it derives from ProgramConverter
and implements ICodeChecker
. Test your class by creating an array of ProgramConverter
objects, some of which are ProgramConverter
s and some of which are ProgramHelper
s. Then call the conversion methods and the code check methods on each item in the array to test which ones implement ICodeChecker
and which ones do not.