Loading ...
Sorry, an error occurred while loading the content.

Re: Template Method Pattern Question (#2)

Expand Messages
  • Alan Shalloway
    ... It ... is ... previous ... organize ... is ... non- ... I m not sure what you mean by a class level equivalent. Please clarify. Alan Shalloway CEO, Net
    Message 1 of 19 , Dec 13, 2007
    View Source
    • 0 Attachment
      --- In leanprogramming@yahoogroups.com, "Max Guernsey, III"
      <Max.Guernsey@...> wrote:
      >
      > This is pertaining to the Template Method Pattern
      > (http://www.netobjectivesrepository.com/TheTemplateMethodPattern).
      >
      > What is the class-level equivalent of the Template Method Pattern?
      > Maybe it's moot. I can only think of examples that are
      > implementations of the Strategy Pattern (off the top of my head).
      It
      > might just the the case where a particular strategy implementation
      is
      > a host for what I believe to be a template method (as per my
      previous
      > post). I'm talking about the case where you have a "big
      > responsibility" and the object in question does nothing but
      organize
      > the efforts of other objects to tackle ensure the responsibility is
      > fulfilled.
      >
      > It doesn't seem like it could be the Union Pattern because that is
      > about commonality amongst members of a set (if I'm not mistaken).
      >
      > It doesn't seem like it could be the Composite Pattern because that
      > is about encapsulating or controlling cardinality.
      >
      > It doesn't seem like it could be the Facade Pattern because there
      is
      > value-added.
      >
      > It doesn't seem like a special case of the Template Pattern and the
      > Strategy Pattern being combined because I swear I've seen it in a
      non-
      > strategy context.
      >
      > The Mediator Pattern, maybe? It definitely organizes how sets of
      > objects interact.
      >
      > Max Guernsey, III
      > http://www.hexsw.com
      >

      I'm not sure what you mean by a class level equivalent. Please
      clarify.
      Alan Shalloway
      CEO, Net Objectives
    • Max Guernsey, III
      ... I m not sure, either. The simple case is, as I said, when you have an implementation of the Strategy Pattern that uses a compositional implementation of
      Message 2 of 19 , Dec 13, 2007
      View Source
      • 0 Attachment
        --- In leanprogramming@yahoogroups.com, "Alan Shalloway"
        <alshall@...> wrote:
        >
        > I'm not sure what you mean by a class level equivalent. Please
        > clarify.
        > Alan Shalloway
        > CEO, Net Objectives
        >

        I'm not sure, either. The simple case is, as I said, when you have
        an implementation of the Strategy Pattern that uses a compositional
        implementation of the Template Method Pattern to do it's job. In
        that case, the class is essentially a "template" for implementing the
        Strategy Pattern in my mind. Like I said, I can't come up with a
        good example off of the top of my head aside from that delineated
        above but I seem to remember doing or seeing it in the past.

        From http://www.netobjectivesrepository.com/TheTemplateMethodPattern :
        "It should be noted that the Template Method Pattern is meant to vary
        the steps in an algorithm"

        This implies that the Template Method Pattern is not for varying
        parts of an object. What I'm thinking about would be something like
        the "Template Object Pattern" but I know of no such thing and I don't
        want to presume to create it if there is already a pattern that fills
        this role.

        Max Guernsey, III
        http://www.hexsw.com
      • Alan Shalloway
        ... the ... vary ... like ... don t ... fills ... Don t worry about the implementation. Worry about what you are trying to accomplish. Strategy is about
        Message 3 of 19 , Dec 13, 2007
        View Source
        • 0 Attachment
          --- In leanprogramming@yahoogroups.com, "Max Guernsey, III"
          <Max.Guernsey@...> wrote:
          >
          > --- In leanprogramming@yahoogroups.com, "Alan Shalloway"
          > <alshall@> wrote:
          > >
          > > I'm not sure what you mean by a class level equivalent. Please
          > > clarify.
          > > Alan Shalloway
          > > CEO, Net Objectives
          > >
          >
          > I'm not sure, either. The simple case is, as I said, when you have
          > an implementation of the Strategy Pattern that uses a compositional
          > implementation of the Template Method Pattern to do it's job. In
          > that case, the class is essentially a "template" for implementing
          the
          > Strategy Pattern in my mind. Like I said, I can't come up with a
          > good example off of the top of my head aside from that delineated
          > above but I seem to remember doing or seeing it in the past.
          >
          > From
          http://www.netobjectivesrepository.com/TheTemplateMethodPattern :
          > "It should be noted that the Template Method Pattern is meant to
          vary
          > the steps in an algorithm"
          >
          > This implies that the Template Method Pattern is not for varying
          > parts of an object. What I'm thinking about would be something
          like
          > the "Template Object Pattern" but I know of no such thing and I
          don't
          > want to presume to create it if there is already a pattern that
          fills
          > this role.
          >
          > Max Guernsey, III
          > http://www.hexsw.com
          >
          Don't worry about the implementation. Worry about what you are trying
          to accomplish.
          Strategy is about encapsulating different algorithms.
          Template is about having _an_ algorithm with different steps.

          Patterns do relate. You can have a compound template method -
          strategy patterns where a template method is implemented with
          strategies. You can have a compound strategy - template method
          pattern where the strategy is implemented with a template method.
          But the implementation is not the important thing - your intent is.

          Alan Shalloway
          CEO, Net Objectives
        • Max Guernsey, III
          ... Thank you, Alan. I m not trying to convey implementation. I m trying to convey intent using implementation. The intent is this: Have an object that
          Message 4 of 19 , Dec 13, 2007
          View Source
          • 0 Attachment
            --- In leanprogramming@yahoogroups.com, "Alan Shalloway" <alshall@...>
            wrote:
            > Don't worry about the implementation. Worry about what you are trying
            > to accomplish.
            > Strategy is about encapsulating different algorithms.
            > Template is about having _an_ algorithm with different steps.
            >
            > Patterns do relate. You can have a compound template method -
            > strategy patterns where a template method is implemented with
            > strategies. You can have a compound strategy - template method
            > pattern where the strategy is implemented with a template method.
            > But the implementation is not the important thing - your intent is.
            >
            > Alan Shalloway
            > CEO, Net Objectives
            >

            Thank you, Alan. I'm not trying to convey implementation. I'm trying
            to convey intent using implementation.

            The intent is this:
            Have an object that represents a structural template as opposed to the
            Template Method Pattern which creates a behavioral template.

            Max Guernsey, III
            http://www.hexsw.com
          • Rob Myers
            You may want to look at Builder Pattern. Abstract Factory Pattern (which I really wish we could rename to Abstraction Factory Pattern) is also quite potent,
            Message 5 of 19 , Dec 13, 2007
            View Source
            • 0 Attachment

              You may want to look at Builder Pattern.  Abstract Factory Pattern (which I really wish we could rename to Abstraction Factory Pattern) is also quite potent, when appropriate.

               

              Beyond that, if you have behavior living in a static method, and you want it to vary, you probably have an actual object that is just screaming to be created.  If you don’t know what it is, just name if Foo.  It’ll tell you after a while.  Let design difficulties speak to (or scream at) you.  Keeping design simple is not always easy right away, but pays dividends.  And not all objects are apparent in the business domain.

               

              From: leanprogramming@yahoogroups.com [mailto:leanprogramming@yahoogroups.com] On Behalf Of Max Guernsey, III
              Sent: Thursday, December 13, 2007 11:28 AM
              To: leanprogramming@yahoogroups.com
              Subject: [leanprogramming] Re: Template Method Pattern Question (#2)

               

              --- In leanprogramming@yahoogroups.com, "Alan Shalloway" <alshall@...>
              wrote:

              > Don't worry about the implementation. Worry about what you are trying
              > to accomplish.
              > Strategy is about encapsulating different algorithms.
              > Template is about having _an_ algorithm with different steps.
              >
              > Patterns do relate. You can have a compound template method -
              > strategy patterns where a template method is implemented with
              > strategies. You can have a compound strategy - template method
              > pattern where the strategy is implemented with a template method.
              > But the implementation is not the important thing - your intent is.
              >
              > Alan Shalloway
              > CEO, Net Objectives
              >

              Thank you, Alan. I'm not trying to convey implementation. I'm trying
              to convey intent using implementation.

              The intent is this:
              Have an object that represents a structural template as opposed to the
              Template Method Pattern which creates a behavioral template.

              Max Guernsey, III
              http://www.hexsw.com


              ______________________________________________________________________
              This email has been scanned by the MessageLabs Email Security System.
              For more information please visit http://www.messagelabs.com/email
              ______________________________________________________________________

            • Alan Shalloway
              ... trying ... I m sorry max, but trying to convey intent through implementation is like trying to convey taste with pictures. It can be done if the person
              Message 6 of 19 , Dec 13, 2007
              View Source
              • 0 Attachment
                --- In leanprogramming@yahoogroups.com, "Max Guernsey, III"
                <Max.Guernsey@...> wrote:

                > Thank you, Alan. I'm not trying to convey implementation. I'm
                trying
                > to convey intent using implementation.

                I'm sorry max, but trying to convey intent through implementation is
                like trying to convey taste with pictures. It can be done if the
                person you are communicating too already knows your intent.

                Alan Shalloway
                CEO, Net Objectives
              • Max Guernsey, III
                ... You must be hungry. Good point, Alan. I will keep that in mind for the future. Max Guernsey, III http://www.hexsw.com
                Message 7 of 19 , Dec 13, 2007
                View Source
                • 0 Attachment
                  --- In leanprogramming@yahoogroups.com, "Alan Shalloway" <alshall@...>
                  wrote:
                  >
                  > I'm sorry max, but trying to convey intent through implementation is
                  > like trying to convey taste with pictures. It can be done if the
                  > person you are communicating too already knows your intent.
                  >
                  > Alan Shalloway
                  > CEO, Net Objectives
                  >

                  You must be hungry.

                  Good point, Alan. I will keep that in mind for the future.

                  Max Guernsey, III
                  http://www.hexsw.com
                • Max Guernsey, III
                  ... So, then, how does one get help when they don t know their own intent? Surely I m not the first person who simply does without being able to articulate
                  Message 8 of 19 , Dec 13, 2007
                  View Source
                  • 0 Attachment
                    --- In leanprogramming@yahoogroups.com, "Alan Shalloway" <alshall@...>
                    wrote:
                    >
                    > I'm sorry max, but trying to convey intent through implementation is
                    > like trying to convey taste with pictures. It can be done if the
                    > person you are communicating too already knows your intent.
                    >
                    > Alan Shalloway
                    > CEO, Net Objectives
                    >

                    So, then, how does one get help when they don't know their own intent?
                    Surely I'm not the first person who simply does without being able to
                    articulate why. It's pretty easy for me to tell what my cats'
                    intentions are; their vocabulary is extremely limited and difficult to
                    extend by comparison to our own. There have to be techniques for
                    helping people like me extract intent from actions... right?

                    Max Guernsey, III
                    http://www.hexsw.com
                  • Max Guernsey, III
                    ... Pattern) is ... to ... I understand everything you just said... or at least I think I do. I do not understand how it pertains to the question. What is
                    Message 9 of 19 , Dec 13, 2007
                    View Source
                    • 0 Attachment
                      --- In leanprogramming@yahoogroups.com, "Rob Myers" <rob@...> wrote:
                      >
                      > You may want to look at Builder Pattern. Abstract Factory Pattern
                      > (which I really wish we could rename to Abstraction Factory
                      Pattern) is
                      > also quite potent, when appropriate.
                      >
                      >
                      >
                      > Beyond that, if you have behavior living in a static method, and you
                      > want it to vary, you probably have an actual object that is just
                      > screaming to be created. If you don't know what it is, just name if
                      > Foo. It'll tell you after a while. Let design difficulties speak
                      to
                      > (or scream at) you. Keeping design simple is not always easy right
                      > away, but pays dividends. And not all objects are apparent in the
                      > business domain.
                      >

                      I understand everything you just said... or at least I think I do. I
                      do not understand how it pertains to the question. What is the
                      origin of the static method? Is that just an example of letting
                      design scream at me?

                      Max Guernsey, III
                      http://www.hexsw.com
                    • Alan Shalloway
                      ... intent? ... to ... Patterns can actually help here because each pattern s intent can be a checklist you use to see if that is necessary in your problem
                      Message 10 of 19 , Dec 13, 2007
                      View Source
                      • 0 Attachment
                        --- In leanprogramming@yahoogroups.com, "Max Guernsey, III"
                        <Max.Guernsey@...> wrote:
                        >

                        > So, then, how does one get help when they don't know their own
                        intent?
                        > Surely I'm not the first person who simply does without being able to
                        > articulate why. It's pretty easy for me to tell what my cats'
                        > intentions are; their vocabulary is extremely limited and difficult
                        to
                        > extend by comparison to our own. There have to be techniques for
                        > helping people like me extract intent from actions... right?
                        >

                        Patterns can actually help here because each pattern's intent can be a
                        checklist you use to see if that is necessary in your problem domain.
                        However, other places to look are other devs (pair) and the customer.

                        And don't get me started on cats. We have more than you can believe. :)

                        Alan Shalloway
                        CEO, Net Objectives
                      • Rob Myers
                        Perhaps set aside, for now, extracting intent from implementation. Instead, extract implementation from intent. One way would be to specify the intent of the
                        Message 11 of 19 , Dec 13, 2007
                        View Source
                        • 0 Attachment

                          Perhaps set aside, for now, extracting intent from implementation.  Instead, extract implementation from intent.

                           

                          One way would be to specify the intent of the behavior in “unit tests”.  There is an intimate connection between programmer tests, Design Patterns, and design considerations such as cohesion, coupling, encapsulation, and redundancy.  Ultimately, test the behavior you want to see from your code, and design for maintainability.  Since that’s like saying “buy low, sell high” we have full three-day courses on TDD and Design Patterns.  There are few things to learn, really, but there’s a lifetime of learning about those few things.  J

                           

                          I find TDD helpful in many ways, but regarding design, I find that I don’t worry about design as much, and I get better (cleaner, simpler, more maintainable) design from not worrying about it.  TDD is a bit of a brain-twister at first, but it is actually quite natural for anyone scientifically, or logically, oriented.  Starting in state A, I invoke transition X, and I get state B.  That’s a statement of the expected behavior, and belongs in a test.  You literally can’t say that in your design, because design is the way the software gets the work done.  The implementation of X is the manifestation of the design.

                           

                          Without the actual constraint of the automated suite of programmer tests, we have to keep every possible contingency in our head while designing.  That was easy when I was hacking out high-speed communication protocol layers 20 years ago (even though I had 9-bit byte machines that handled character data and binary data differently).  But in retrospect, I would’ve been far more productive had I had PascalUnit and FortranUnit (and BUnit and AdaUnit and Modula2Unit and PL6Unit…)

                           

                          Another thing to try is to program with another programmer.  Discuss the needed software behavior and design issues as peers, and try out whatever seems simplest (simple in the code, not always *easiest* for you to write).  You’ll both probably learn something new, and your design may be better than either of you would have written alone.

                           

                           

                          From: leanprogramming@yahoogroups.com [mailto:leanprogramming@yahoogroups.com] On Behalf Of Max Guernsey, III
                          Sent: Thursday, December 13, 2007 1:36 PM
                          To: leanprogramming@yahoogroups.com
                          Subject: [leanprogramming] Re: Template Method Pattern Question (#2)

                           

                          --- In leanprogramming@yahoogroups.com, "Alan Shalloway" <alshall@...>
                          wrote:

                          >
                          > I'm sorry max, but trying to convey intent through implementation is
                          > like trying to convey taste with pictures. It can be done if the
                          > person you are communicating too already knows your intent.
                          >
                          > Alan Shalloway
                          > CEO, Net Objectives
                          >

                          So, then, how does one get help when they don't know their own intent?
                          Surely I'm not the first person who simply does without being able to
                          articulate why. It's pretty easy for me to tell what my cats'
                          intentions are; their vocabulary is extremely limited and difficult to
                          extend by comparison to our own. There have to be techniques for
                          helping people like me extract intent from actions... right?

                          Max Guernsey, III
                          http://www.hexsw.com


                          ______________________________________________________________________
                          This email has been scanned by the MessageLabs Email Security System.
                          For more information please visit http://www.messagelabs.com/email
                          ______________________________________________________________________

                        • Rob Myers
                          Max, It s very possible that I ve misinterpreted the original question. You asked What is the class-level equivalent of the Template Method Pattern? and I
                          Message 12 of 19 , Dec 13, 2007
                          View Source
                          • 0 Attachment

                            Max,

                             

                            It’s very possible that I’ve misinterpreted the original question.  You asked “What is the class-level equivalent of the Template Method Pattern?” and I may have heard “How do I implement a static Template Method?”  It’s something I’ve been asked before, perhaps…

                             

                            Beyond that, I’m not sure I understand what you’re asking.

                             

                            When I use patterns, I tend not to mull over which one to use before I’m coding.  I look for things to refactor, and when I see a familiar issue or structure arise in the design, I may then ask myself “Is this a <whatever> Pattern?”  Thinking in those terms helps me get out of a pickle, but I don’t force a “full” implementation of the pattern.  If I need some behavior, and I know that I can get it most easily by implementing a Design Pattern, I’ll encourage that pattern through unit tests.  The pattern gets implemented fully, perhaps, but it may not have all the bells and whistles.

                             

                            Patterns don’t really provide you with good reusable designs:  You can’t build one and use it all over the place, and there’s no one right implementation of the pattern.  I’m sure someone is building a drag-and-drop patterns menu for an IDE, and they’ll make lots of money from it, but I won’t buy it.  Patterns are *examples of good designs* that allow for some reuse of objects within the system.

                             

                            Oh!  That reminds me.  Has anyone mentioned here the three big design lessons from the Gang of Four?

                             

                            1.       Design to abstractions:  Client objects tend to talk to abstractions (abstract classes or interfaces, but those are implementation details, not design issues).  That way the client object code will work with any concrete type that implements the abstract type.

                            2.      Favor composition over inheritance:  Use inheritance to *categorize* objects into an abstraction, not to forcefully inherit concrete behaviors and interfaces (i.e., “specialization”)

                            3.      Encapsulate variation:  Whatever varies, make that an object, and remember the first two items, above.

                             

                            If you study Strategy, you’ll see that it does all these things.  I call Strategy the “hydrogen atom” of patterns because:

                             

                            1.      It contains all three of the “subatomic particles” listed above (okay, so it’s heavy hydrogen)

                            2.      It occurs naturally, and appears everywhere in the universe

                            3.      If everything were a hydrogen atom, we wouldn’t be having this discussion  J  Don’t assume that everything is a Strategy, either.

                            4.      We should learn from the periodic table, but not memorize it.  That’s wasted effort.  We must learn the underlying quantum principles, instead.

                            5.      Rob is a geek.

                             

                             

                            From: leanprogramming@yahoogroups.com [mailto:leanprogramming@yahoogroups.com] On Behalf Of Max Guernsey, III
                            Sent: Thursday, December 13, 2007 1:36 PM
                            To: leanprogramming@yahoogroups.com
                            Subject: [leanprogramming] Re: Template Method Pattern Question (#2)

                             

                            --- In leanprogramming@yahoogroups.com, "Rob Myers" <rob@...> wrote:

                            >
                            > You may want to look at Builder Pattern. Abstract Factory Pattern
                            > (which I really wish we could rename to Abstraction Factory
                            Pattern) is
                            > also quite potent, when appropriate.
                            >
                            >
                            >
                            > Beyond that, if you have behavior living in a static method, and you
                            > want it to vary, you probably have an actual object that is just
                            > screaming to be created. If you don't know what it is, just name if
                            > Foo. It'll tell you after a while. Let design difficulties speak
                            to
                            > (or scream at) you. Keeping design simple is not always easy right
                            > away, but pays dividends. And not all objects are apparent in the
                            > business domain.
                            >

                            I understand everything you just said... or at least I think I do. I
                            do not understand how it pertains to the question. What is the
                            origin of the static method? Is that just an example of letting
                            design scream at me?

                            Max Guernsey, III
                            http://www.hexsw.com

                             

                          • Max Guernsey, III
                            ... be a ... domain. ... customer. ... believe. :) ... I know you have a lot of cats. I bet that I still have more per square foot of housing, though. :) To
                            Message 13 of 19 , Dec 13, 2007
                            View Source
                            • 0 Attachment
                              --- In leanprogramming@yahoogroups.com, "Alan Shalloway"
                              <alshall@...> wrote:
                              >
                              > Patterns can actually help here because each pattern's intent can
                              be a
                              > checklist you use to see if that is necessary in your problem
                              domain.
                              > However, other places to look are other devs (pair) and the
                              customer.
                              >
                              > And don't get me started on cats. We have more than you can
                              believe. :)
                              >
                              > Alan Shalloway
                              > CEO, Net Objectives
                              >

                              I know you have a lot of cats. I bet that I still have more per
                              square foot of housing, though. :)

                              To be honest, I simply don't understand at all. I don't think about
                              patterns ahead of time. I use them as tools to communicate to others
                              what I've done in the past. Are you suggesting that I should think
                              about the patterns in the problem before a solution emerges?

                              The motivation of the Template Method Pattern (per
                              http://www.netobjectivesrepository.com/TheTemplateMethodPattern)
                              is "Abstract out the skeletal steps of an algorithm." I snipped out
                              the part regarding subclassing. So I guess the question is "what is
                              the pattern for which the motivation is 'Abstract out the skeletal
                              structure of a type?'"

                              ...or maybe I'm asking the wrong question.

                              Max Guernsey, III
                              http://www.hexsw.com
                            • Alan Shalloway
                              ... That s exactly what I am saying. In fact, you don t get to the real value of patterns until you start doing that. For example, let s say you ve got a
                              Message 14 of 19 , Dec 14, 2007
                              View Source
                              • 0 Attachment
                                --- In leanprogramming@yahoogroups.com, "Max Guernsey, III"
                                <Max.Guernsey@...> wrote:
                                >
                                > To be honest, I simply don't understand at all. I don't think about
                                > patterns ahead of time. I use them as tools to communicate to others
                                > what I've done in the past. Are you suggesting that I should think
                                > about the patterns in the problem before a solution emerges?
                                >

                                That's exactly what I am saying. In fact, you don't get to the real
                                value of patterns until you start doing that.

                                For example, let's say you've got a routine working. Nice code, all
                                that. Now, you have another case where you need a function very much
                                like this except for the fact that the way you implement a couple of
                                the steps are different. What are your choices?
                                1) copy and paste and change the sections that need to vary?
                                2) put if's in the sections that vary?

                                OR, if you know the intention of the template method pattern, use
                                that. Now if you also know the way to refactor code and improve your
                                design, the way you'll do this is you'll first refactor so the basic
                                routine used is placed in a base class (abstract) with the variations
                                of the case you already have in a derivation. Then, you implement the
                                second case in a second, derived class.

                                Won't be back on-line until the weekend (long day today) so if you
                                don't hear from me - just be patient.

                                Alan Shalloway
                                CEO, Net Objectives
                              • Max Guernsey, III
                                ... real ... all ... much ... of ... your ... basic ... variations ... the ... Patience and Tolerance are my two middle names... I m not trying to be
                                Message 15 of 19 , Dec 14, 2007
                                View Source
                                • 0 Attachment
                                  --- In leanprogramming@yahoogroups.com, "Alan Shalloway"
                                  <alshall@...> wrote:
                                  >
                                  > That's exactly what I am saying. In fact, you don't get to the
                                  real
                                  > value of patterns until you start doing that.
                                  >
                                  > For example, let's say you've got a routine working. Nice code,
                                  all
                                  > that. Now, you have another case where you need a function very
                                  much
                                  > like this except for the fact that the way you implement a couple
                                  of
                                  > the steps are different. What are your choices?
                                  > 1) copy and paste and change the sections that need to vary?
                                  > 2) put if's in the sections that vary?
                                  >
                                  > OR, if you know the intention of the template method pattern, use
                                  > that. Now if you also know the way to refactor code and improve
                                  your
                                  > design, the way you'll do this is you'll first refactor so the
                                  basic
                                  > routine used is placed in a base class (abstract) with the
                                  variations
                                  > of the case you already have in a derivation. Then, you implement
                                  the
                                  > second case in a second, derived class.
                                  >
                                  > Won't be back on-line until the weekend (long day today) so if you
                                  > don't hear from me - just be patient.
                                  >
                                  > Alan Shalloway
                                  > CEO, Net Objectives
                                  >

                                  "Patience" and "Tolerance" are my two middle names...

                                  I'm not trying to be combative. I seriously do not get it. Maybe
                                  I'm just extremophilic and you guys are like "It's oxygen... just
                                  breath!" and I'm all like "It burns! It burns!"

                                  So, in your mind, is it not possible to use the Template Method
                                  Pattern without knowing that it is, in fact, the Template Method
                                  Pattern? I remember, in the first Net Objectives class I went to
                                  with, talking with Scott Bain about something and using an example to
                                  augment the conversation. "So you're using a Chain of
                                  Responsibility, there," he said. After some explanation on his part,
                                  there was real "Aha!" moment for me: In spite of my resistence to
                                  Design Patterns (I have a serious case of NIH syndrome), I'd been
                                  using them; whether I liked it or not.

                                  Is there no value in using Design Patterns to articulate what I've
                                  done? ...and, on the opposite end of the problem, what is the value
                                  I get from thinking "I'm going to use a Template Method, here," and
                                  then doing it as opposed to just doing what comes naturally (which
                                  just so happens to be something that people call "the Template Method
                                  Pattern")? ...or am I asking the entirely wrong questions, here?

                                  Apparently I like ellipses, today.

                                  Max Patience Tolerance Guernsey, III
                                  http://www.hexsw.com
                                • Alan Shalloway
                                  ... to ... part, ... Of course you can use them this way. I did things like that with other patterns. However, I would suggest that this is intuiting the
                                  Message 16 of 19 , Dec 14, 2007
                                  View Source
                                  • 0 Attachment
                                    --- In leanprogramming@yahoogroups.com, "Max Guernsey, III"
                                    <Max.Guernsey@...> wrote:
                                    >
                                    > So, in your mind, is it not possible to use the Template Method
                                    > Pattern without knowing that it is, in fact, the Template Method
                                    > Pattern? I remember, in the first Net Objectives class I went to
                                    > with, talking with Scott Bain about something and using an example
                                    to
                                    > augment the conversation. "So you're using a Chain of
                                    > Responsibility, there," he said. After some explanation on his
                                    part,
                                    > there was real "Aha!" moment for me: In spite of my resistence to
                                    > Design Patterns (I have a serious case of NIH syndrome), I'd been
                                    > using them; whether I liked it or not.

                                    Of course you can use them this way. I did things like that with
                                    other patterns. However, I would suggest that this is intuiting the
                                    issues in the pattern. If you understand what the pattern is from a
                                    motivational point of view, you'll find you can use them a lot more.
                                    Using patterns the way are is good, and helpful to describe what you
                                    did. But it's kind of like using the wrong side of a knife. It
                                    helps, but it helps more when you use patterns from what their
                                    intention is. Knowing the entire pattern - knowing the forces that
                                    need to be resolved - not just how you solved it. This enables you
                                    to use patterns before you've defined your classes. This enables the
                                    patterns to help you define your classes. This is where their real
                                    power comes in.


                                    Alan Shalloway
                                    CEO, Net Objectives
                                  • Max Guernsey, III
                                    ... the ... a ... more. ... you ... the ... Fair enough. I think I m on board with it though I admit to intuiting more often than I should. When you don t
                                    Message 17 of 19 , Dec 14, 2007
                                    View Source
                                    • 0 Attachment
                                      --- In leanprogramming@yahoogroups.com, "Alan Shalloway"
                                      <alshall@...> wrote:
                                      >
                                      > Of course you can use them this way. I did things like that with
                                      > other patterns. However, I would suggest that this is intuiting
                                      the
                                      > issues in the pattern. If you understand what the pattern is from
                                      a
                                      > motivational point of view, you'll find you can use them a lot
                                      more.
                                      > Using patterns the way are is good, and helpful to describe what
                                      you
                                      > did. But it's kind of like using the wrong side of a knife. It
                                      > helps, but it helps more when you use patterns from what their
                                      > intention is. Knowing the entire pattern - knowing the forces that
                                      > need to be resolved - not just how you solved it. This enables you
                                      > to use patterns before you've defined your classes. This enables
                                      the
                                      > patterns to help you define your classes. This is where their real
                                      > power comes in.
                                      >
                                      >
                                      > Alan Shalloway
                                      > CEO, Net Objectives
                                      >

                                      Fair enough. I think I'm on board with it though I admit to
                                      intuiting more often than I should.

                                      When you don't know of a pattern driven by motivation, how do you
                                      find it? Do you ask your peers? Do you investigate the possibile
                                      existence of an undocumented pattern? ...something else?

                                      Max Guernsey, III
                                      http://www.hexsw.com
                                    • Scott L. Bain
                                      It Depends :) The template method pattern is in use when you abstract out the steps of an algorithm, using typical functional decomposition, and then allow
                                      Message 18 of 19 , Dec 17, 2007
                                      View Source
                                      • 0 Attachment
                                        "It Depends" :)

                                        The template method pattern is in use when you abstract out the steps
                                        of "an" algorithm, using typical functional decomposition, and then
                                        allow the steps of "the" algorithm to vary in subclasses.

                                        A typical misuse of the pattern is to use it to vary many diffrent
                                        algorithms together; this often inhibits testing and reuse, and makes
                                        systems needlessly inflexible.

                                        For example:

                                        abstract class OrderProcessing {
                                        void notAGreatTemplate(){
                                        double orderTotal = getOrderTotal();
                                        double taxes = chargeTaxes(orderTotal);
                                        bool goodAddress verifyAddress();
                                        if goodAddress {
                                        notifyCustomer();
                                        sendBill();
                                        } else {
                                        sendAlert();
                                        }
                                        private abstract getOrderTotal();
                                        private abstract chargeTaxes(double amount);
                                        private abstract verifyAddress();
                                        private abstract notifyCustomer();
                                        private sendBill();
                                        private sendAlert();
                                        }

                                        This is varying *several* algorithms together. If I really do want
                                        to constrain the system so that tax calculations (etc...) can never
                                        be used in any other context, then perhaps this is correct, but that
                                        would probably be a rare case. Most people who use the pattern like
                                        this do not want that effect specifically.

                                        I would use a set of strategies and an abstract factory for the
                                        problem above, in most cases.

                                        -S-


                                        --- In leanprogramming@yahoogroups.com, "Max Guernsey, III"
                                        <Max.Guernsey@...> wrote:
                                        >
                                        > This is pertaining to the Template Method Pattern
                                        > (http://www.netobjectivesrepository.com/TheTemplateMethodPattern).
                                        >
                                        > What is the class-level equivalent of the Template Method Pattern?
                                        > Maybe it's moot. I can only think of examples that are
                                        > implementations of the Strategy Pattern (off the top of my head).
                                        It
                                        > might just the the case where a particular strategy implementation
                                        is
                                        > a host for what I believe to be a template method (as per my
                                        previous
                                        > post). I'm talking about the case where you have a "big
                                        > responsibility" and the object in question does nothing but
                                        organize
                                        > the efforts of other objects to tackle ensure the responsibility is
                                        > fulfilled.
                                        >
                                        > It doesn't seem like it could be the Union Pattern because that is
                                        > about commonality amongst members of a set (if I'm not mistaken).
                                        >
                                        > It doesn't seem like it could be the Composite Pattern because that
                                        > is about encapsulating or controlling cardinality.
                                        >
                                        > It doesn't seem like it could be the Facade Pattern because there
                                        is
                                        > value-added.
                                        >
                                        > It doesn't seem like a special case of the Template Pattern and the
                                        > Strategy Pattern being combined because I swear I've seen it in a
                                        non-
                                        > strategy context.
                                        >
                                        > The Mediator Pattern, maybe? It definitely organizes how sets of
                                        > objects interact.
                                        >
                                        > Max Guernsey, III
                                        > http://www.hexsw.com
                                        >
                                      Your message has been successfully submitted and would be delivered to recipients shortly.