Design Guidelines Update: "Core" Method pattern

Minor tweaks to this guideline to line up with what is, I believe, common practice already..

As always questions, comments and annotations to me, and the full guidelines can be found here:  http://www.gotdotnet.com/team/libraries

---------- 

*      It is recommended that you provide customization through protected  (family) methods.

The public interface of a base class should provide a rich set of functionality for the consumer of that class.  However, customizers of that class often want to implement the fewest methods possible to provide that rich set of functionality to the consumer.  To meet this goal, provide a set of non-virtual or final public methods that call through to a single (or very small set of) protected (family) method with the “Core” suffix that provides implementations for such a method.

public Control{
   //…
   public void SetBounds(int x, int y, int width, int height){

      …
      SetBoundsCore (…);
   }
  

   public void SetBounds(int x, int y, int width, int  

   height, BoundsSpecified specified){

       …
       SetBoundsCore (…);
   }

   protected virtual void SetBoundsCore(int x, int y, int width, int

      height, BoundsSpecified specified){
         // Do the real work here.
      }
   }

Annotation (BradA): Notice in a few parts of the Framework v1.0 we used the suffix “Impl” for this convention.  In retrospect “Core” is more common and is not an abbreviation, so we choice to standardize on it.

Published 18 December 03 04:10 by BradA

Comments

# Andy Smith said on December 18, 2003 5:26 PM:
I've also seen an "Internal" suffix in some Framework v1 classes (can't remember which). This kind of struck me as odd, as they were protected methods, suffixed with a different protection level name. "Core" seems like a much better name.
# Jim Argeropoulos said on December 19, 2003 9:44 AM:
In the Mac world it was always "Self", but that is/was another world
# ssge said on December 19, 2003 8:21 PM:
I would prefer "Internal". I want to provide some reasoning behind it: 1. The cumulative for “protected” and “private” is exactly internal. A user cannot invoke the internal methods 2. The term “Core” is overloaded. It also can be used in other contexts and have other meanings not akin to the implementation pattern. In addition to the suffixes Implementation and Self I have seen Real and Work.
# Brad Abrams said on December 19, 2003 9:26 PM:
Actually, there is a huge difference between protected and private members... They are not in the same class... protected members can be called by basicly anyone, all you have to do is subclass the class.. Internal members can only be called from types in the same assembly.
# Anonymous said on December 20, 2003 5:05 PM:
It's a shame that you either neglected to mention that this is more commonly known as the 'Template Method' idiom from the GoF "Design Patterns" book, or failed to clarify any differences from it.
# Brad Abrams said on December 21, 2003 4:16 PM:
That is a good point on the Template Method pattern. I beleive the Template Method generally has multiple method calls funneling through one protected member. Where this pattern maybe one or more.
# Ken Brubaker said on February 20, 2004 10:48 AM:
For my own reference, I thought I'd compile a quick list of design guidelines added by Brad Abrams, et al.
# sophie said on March 29, 2004 2:04 PM:
can you give me a design of the core!
New Comments to this post are disabled

Search

Go

This Blog

Syndication

Page view tracker