Design Guidelines Update: “Core” Method pattern



style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> "urn:schemas-microsoft-com:office:office" />


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Minor tweaks to this guideline to
line up with what is, I believe, common practice already..


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">As always questions, comments and
annotations to me, and the full guidelines can be found
here: 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">  href="http://www.gotdotnet.com/team/libraries">http://www.gotdotnet.com/team/libraries


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">———- face=Arial size=2> style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 


style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol"> height=11 alt=* src="cid:image001.gif@01C3C54D.651C6820" width=12> face="Times New Roman" size=1> style="FONT: 7pt 'Times New Roman'">     
It is recommended that you provide
customization through protected  (family) methods.


style="FONT-SIZE: 10pt">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.


size=1>public Control{
  
//…
   public void SetBounds(int x, int y, int width, int
height){


size=1>     

      SetBoundsCore (…);
  
}
  


size=1>   public void SetBounds(int x,
int y, int width, int  


size=1>   height, BoundsSpecified
specified){


size=1>      

       SetBoundsCore (…);
  
}


size=1>   protected virtual void
SetBoundsCore(int x, int y, int width, int


size=1>      height,
BoundsSpecified specified){
     
   // Do the real work here.
     
}
   }


style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 4pt; BACKGROUND: #e9fdf3; PADDING-BOTTOM: 1pt; MARGIN-LEFT: 0.25in; BORDER-LEFT: windowtext 1pt solid; MARGIN-RIGHT: 0in; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-element: para-border-div">

size=1>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.


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">

Comments (8)

  1. Andy Smith says:

    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.

  2. Jim Argeropoulos says:

    In the Mac world it was always "Self", but that is/was another world

  3. ssge says:

    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.

  4. Brad Abrams says:

    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.

  5. Anonymous says:

    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.

  6. Brad Abrams says:

    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.

  7. Ken Brubaker says:

    For my own reference, I thought I’d compile a quick list of design guidelines added by Brad Abrams, et al.

  8. sophie says:

    can you give me a design of the core!

Skip to main content