locked
DesignPatterns: What does scope of a design pattern ( either Class or Object) explains? RRS feed

  • Question

  • DesignPatterns: What does scope of a design pattern ( either Class or Object) explains?

    Please clear the confusion of how to identify/conclude the scope of a design pattern?

    thanks


    HydPhani
    Monday, August 1, 2011 2:37 PM

All replies

  • Hi

    DesignPatterns are solutions to the recurring problems faced in application developement....

    Dont confuse patterns are related to Class or Object..these are solution to design  problem..

    For example...If my requirement is loading configuration settings only once when application starts and wanted to use till application closes

    This is common problem can be solved by using SingletonPattern

    Like every recuring design problem is addressed by these patterns....

    Check GangOfFour patterns, these are most useful patterns used

    http://www.dofactory.com/Patterns/Patterns.aspx 

    also check

    http://msdn.microsoft.com/en-us/practices/default.aspx

    Hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    • Proposed as answer by Brad Semrad Thursday, August 4, 2011 2:13 PM
    Monday, August 1, 2011 4:06 PM
  • Hi Kris,

    I got some other forum answered the question in this way, each design pattern solution either contains Inheritance or composition while building it (as a strategy), if it uses inheritance, its in  'Class'  scope and if it uses composition - 'its in 'Object' scope...

    Please reply, if you have a differ in this perception, appreciate your time

    ref : http://www.gofpatterns.com/design-patterns/module2/design-pattern-scope.php 

    thanks


    HydPhani
    Thursday, August 4, 2011 2:52 PM
  • Hi

    "A design pattern is a known solution applicable to a concrete problem that might occur during implementation"

    OfCourse, every class should have some sort of relation with other class could be Associations (association, aggregation and composition), Generalization and Dependency...

    When you are implementing solution, You will end up using these relations though you are not considered any of the design patterns....The design patterns force you towards achieving your solution this involves any of the relations mentioned above.

    Just think you are about to create different Loggers based onsome businedd rule in application...What you do is

    you create interface and logger classes as

      public interface ILogger
        {
          void Log(string message);
        }
    
        public class TextLogger : ILogger
        {
          public void Log(string message)
          {
            //logging information into text
          }
        }
    
        public class DBLogger : ILogger
        {
    
          public void Log(string message)
          {
            //DB related logging
          }
        }
    

    and started using like in application

     ILogger logger = useDBLogger ? new DBLogger() : (ILogger)new TextLogger();
    

    This solution works well until you introduced one more logger.....

    From this type of problem Factory Pattern has come up

    public class LoggerFactory
        {
          public ILogger CreateLogger(LoggerType logger)
          {
            if (logger == LoggerType.Text)
            {
              return new TextLogger();
            }
            else if (logger == LoggerType.DB)
            {
              return new DBLogger(); 
            }
          }
        }
    

    This solves the problem that adding more loggers....

    If you observe, We are using classes same way...but with factory pattern we arranged in different class the same thing....

    Hope this clears...



    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    Thursday, August 4, 2011 4:50 PM
  • I guess no body is actually answering his question and in his second message he answered it himself. Yes first classification of design patterns is the scope that where they are at class level or object level. The second classification is the type like creational, structural and behavioral. The difference between class and object patterns are that class patterns deal with relationships between classes and their subclasses, these relationships are estabilished through inheritance so they are static and fixed at compile time. Object pattern deals with object relationships, which can change at runtime and are more dynamic. Most patterns are at object level. For creational patterns only the factory method pattern is at class level, rest are all at object, for structural patterns only adapter is at class level, rest all at object level, but adpater also has an object level too. For behavioural we have interpreter and template method at class rest all at object level.

     

    Hope it answers your question Hyd phani.

     

    Ayub Latif

    Wednesday, September 21, 2011 7:48 AM
  • Thanks Ayub, Appreciate your reply,

    your answer has nice hints to remember those design pattern of class and object level. Yes I got the theory of it..

    Another followup question is : As we are aware that a design pattern can be implemented either by subclassing (Inheritance) or by Interfacing(composition), In such case, as implementation can have choice,  how does this pattern scope matters to us?

    Please anyone clarify...

    thanks


    HydPhani
    Wednesday, September 21, 2011 8:25 AM
  • Through class patterns the relationships are fixed and cannot be created on the fly as they focus on class relationships, while with object patterns object relationships can change at run time according to specific case.  

    Wednesday, September 21, 2011 11:12 AM
  • Hi ,

    Design patterns could be defined as "DesignPatterns are solutions to the recurring problems faced in application developement".  The classifications are just a way to manage the patterns, nothing more than that.  There may be new patterns emerge and there can be compund and complex patterns within the existing patterns. If a compound pattern has a inheritance and composition together then which category you classify it? . So I would suggest just don't tie with classifications, but go with solutions for problems. If there is pattern could solve your problem then adapt it or create your own pattern.

    So again the definition goes with "DesignPatterns are solutions to the recurring problems faced in application developement"

    Good Luck!

    Monday, July 30, 2012 10:37 AM