Access the full text.
Sign up today, get DeepDyve free for 14 days.
CHAPTER 10 ■ ■ ■ Interfaces are closely related to abstract classes that have all members abstract. A Simple Example The following code defines the interface IScalable and the class TextObject, which implements the interface, meaning that it contains implementations of all the functions defined in the interface: public class DiagramObject public DiagramObject() {} interface IScalable void ScaleX(float factor); void ScaleY(float factor); // A diagram object that also implements IScalable public class TextObject: DiagramObject, IScalable public TextObject(string text) this.text = text; // implementing IScalable.ScaleX() public void ScaleX(float factor) // scale the object here. // implementing IScalable.ScaleY() public void ScaleY(float factor) // scale the object here. 85 86 CH APTER 10 ■ INTERFACES private string text; class Test public static void Main() TextObject text = new TextObject("Hello"); IScalable scalable = (IScalable) text; scalable.ScaleX(0.5F); scalable.ScaleY(0.5F); This code implements a system for drawing diagrams. All the objects derive from DiagramObject, so they can implement common virtual functions (not shown in this example). Some of the objects can be scaled, and this is expressed by the presence of an implementation of the IScalable interface. Listing the interface name with the base class name for TextObject indicates that TextObject implements the interface. This means
Published: Jan 1, 2005
Read and print from thousands of top scholarly journals.
Already have an account? Log in
Bookmark this article. You can see your Bookmarks on your DeepDyve Library.
To save an article, log in first, or sign up for a DeepDyve account if you don’t already have one.
Copy and paste the desired citation format or use the link below to download a file formatted for EndNote
Access the full text.
Sign up today, get DeepDyve free for 14 days.
All DeepDyve websites use cookies to improve your online experience. They were placed on your computer when you launched this website. You can change your cookie settings through your browser.