Implementation patterns – Class

By | 15 June, 2013

The idea of classes goes back long before Plato. The platonic solids were classes, instances of which could be seen in the world. The platonic sphere was absolutely perfect but insubstantial. The spheres around us we could touch, but they were all imperfect in some way.
Object-oriented programming picked up on this idea by way of later western philosophers, dividing programs into classes, which are general descriptions of a whole set of similar things, and objects, which are the things themselves.
Classes are important for communication because they describe, potentially, many specific things. Class-level patterns have the largest span of any of the implementation patterns. Design patterns, by contrast, generally talk about the relationships between classes.
The following patterns appear in this chapter:

  • Class—Use a class to say, “This data goes together and this logic goes with it.”
  • Simple Superclass Name—Name the roots of class hierarchies with simple names drawn from the same metaphor.
  • Qualified Subclass Name—Name subclasses to communicate the similarities and differences with a superclass.
  • Abstract Interface—Separate the interface from the implementation.
  • Interface—Specify an abstract interface which doesn’t change often with a Java interface.
  • Versioned Interface—Extend interfaces safely by introducing a new subinterface.
  • Abstract Class—Specify an abstract interface which will likely change with an abstract class.
  • Value Object—Write an object that acts like a mathematical value.
  • Specialization—Clearly express the similarities and differences of related computations.
  • Subclass—Express one-dimensional variation with a subclass.
  • Implementor—Override a method to express a variant of a computation.
  • Inner Class—Bundle locally useful code in a private class.
  • Instance-specific Behavior—Vary logic by instance.
  • Conditional—Vary logic by explicit conditionals.
  • Delegation—Vary logic by delegating to one of several types of objects.
  • Pluggable Selector—Vary logic by reflectively executing a method.
  • Anonymous Inner Class—Vary logic by overriding one or two methods right in the method that is creating a new object
  • Library Class—Represent a bundle of functionality that doesn’t fit into any object as a set of static methods.

 

Scheme extracted from the book "Implementation patterns", chapter 5: class (Kent Beck)

Source:  Implementation Patterns: Kent Beck: 9780321413093: Amazon.com: Books

Leave a Reply

Your email address will not be published. Required fields are marked *