Chapter 7. Polymorphism and Some Final Object Concepts

Earlier in this book, we introduced three key mechanisms that are required of an object-oriented programming language (OOPL). We already discussed how the C# language implements two of these concepts.

By way of review:

  • We can create our own user-defined types, also known as classes, to model objects of arbitrary complexity, as we discussed in Chapter 3.

  • We can arrange these types into class hierarchies to take advantage of the inheritance mechanism of OO languages, as we discussed in Chapter 5.

This chapter introduces the third essential OOPL feature, known as polymorphism, which simplifies code maintenance by allowing different objects belonging to different calls to respond to the same method call in different ways.

In addition to polymorphism, this chapter wraps up our initial discussions of OO concepts with a few "special topics"—things that you don't necessarily need to know when you're first setting out to use the technology, but are valuable to know as you become adept with the basics.

Some of the topics covered include the following:

  • How programming constructs known as abstract classes and interfaces can be used to specify what an object's mission should be without going to the trouble of specifying the details of how the object is to carry out that mission, and also why we'd want to be able to do so

  • How an object can have a "split personality" by exhibiting the behaviors of two or more different types of objects

  • Creative ways for an entire class of objects to easily and efficiently share data without breaking the spirit of encapsulation

  • How static members can be defined that are associated with a class instead of with an instance of a class

  • How to define a constant whose value can't be changed once it's initially set

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset