none
Architectural Layers Vs Design Patterns RRS feed

  • Question

  • Hi

     

    In any business application , It is better to have  UI, Application, Business and Infrastructure layers.

     

    For any architect,  it is said that sound knowledge of design pattern is a must.

    I also come across  it is not possible for anyone to remember the implementations of all kind of design pattern.

     

    But an architect should be in a position to choose a best suited design pattern for the given business problem.

     

    When the application is being designed/architected ,

     

    1)  should the design patterns be implemented in all the 4 layers OR it makes sense if the design patterns are applied in any specific layers?

     

    If we decide to consider accommodating design patterns in all layers ,

     

     2)  is it good to have the same pattern implemented in all layers(of course for UI we have MVC, MVP, MVVM) ?

         

      

    3)   Is it good to have different patterns in different layers ?

    4)   Is it good to have many design patterns in a single layer ?

    Thanks

    Devasena


    Ace
    Tuesday, April 13, 2010 2:22 PM

Answers

  • Hi Devasena,

    Design Patterns are well known patterns for solving technical problems in a way that has proven itself many times and about which you can communicate about. In that sense, the original Design Patterns as identified by Eric Gamma et al are not related to any particular layer. Martin Fowler however, has identified some more domain-specific patterns that are essentially variants of the technical patterns and are targetted at building architectures. You can read more about that here.

    The original guidelines by Gamma was to consider patterns when doing a big upfront design, but since then they have shifted their ideas to working towards patterns. So if you're building a system and use something like Evolutionary Design, every time you refactor your code and you find something that resembleds a pattern, consider replacing it with the actual pattern implementation. It really helps communicate your design and your ideas. Nevertheless, be carefull not to start seeing patterns as a goal, but use them as a means to an end.

    Hope this helps,

    • Marked as answer by Devasena_ace Thursday, April 15, 2010 7:58 AM
    Tuesday, April 13, 2010 4:29 PM

All replies

  • Greetings,

    Design patterns are mainly used for solving software engineering problems. 

    Hope this helps

    Take Care

    PL

     

     

     


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:38 PM
  • Greetings,

    Model-View-Presenter

    In MVP, the Presenter contains the the UI business logic for the View. All invocations from the View delegate directly to Presenter. The Presenter is also decoupled directly from the View and talks to it through an interface. This is to allow mocking of the View in a unit test. One common attribute of MVP is that there has to be a lot of two-way dispatching. For example, when someone clicks the "Save" button, the event handler delegates to the Presenter's "OnSave" method. Once the save is completed, the Presenter will then call back the View through it's interface so that the View can display that the save has completed.

    MVP tends to be a very natural pattern for achieving separated presentation in Web Forms. The reason is because the View is always created first by the ASP.NET runtime. You can find out more about both variants.
    Two primary variations

    Passive View: The View is as as dumb as possible and contains almost zero logic. The Presenter is a middle man that talks to the View and the Model. The View and Model are completely shielded from one another. The Model may raise events, but the Presenter subscribes to them for updating the View. In Passive View there is no direct data binding, instead the View exposes setter properties which the Presenter uses to set the data. All state is managed in the Presenter and not the View.

        * Pro: maximum testability surface; clean separation of the View and Model
        * Con: more work (for example all the setter properties) as you are doing all the data binding yourself.

    Supervising Controller: The Presenter handles user gestures. The View binds to the Model directly through data binding. In this case it's the Presenter's job to pass off the Model to the View so that it can bind to it. The Presenter will also contain logic for gestures like pressing a button, navigation, etc.

        * Pro: by leveraging databinding the amount of code is reduced.
        * Con: there's less testable surface (because of data binding), and there's less encapsulation in the View since it talks directly to the Model.

    Model-View-Controller

    In the MVC, the Controller is responsible for determining which View is displayed in response to any action including when the application loads. This differs from MVP where actions route through the View to the Presenter. In MVC, every action in the View correlates with a call to a Controller along with an action. In the web each action involves a call to a URL on the other side of which there is a Controller who responds. Once that Controller has completed it's processing, it will return the correct View. The sequence continues in that manner throughout the life of the application:

        Action in the View
            -> Call to Controller
            -> Controller Logic
            -> Controller returns the View.

    One other big difference about MVC is that the View does not directly bind to the Model. The view simply renders, and is completely stateless. In implementations of MVC the View usually will not have any logic in the code behind. This is contrary to MVP where it is absolutely necessary as if the View does not delegate to the Presenter, it will never get called.
    Presentation Model

    One other pattern to look at is the Presentation Model pattern. In this pattern there is no Presenter. Instead the View binds directly to a Presentation Model. The Presentation Model is a Model crafted specifically for the View. This means this Model can expose properties that one would never put on a domain model as it would be a violation of separation-of-concerns. In this case, the Presentation Model binds to the domain model, and may subscribe to event coming from that Model. The View then subscribes to events coming from the Presentation Model and updates itself accordingly. The Presentation Model can expose commands which the view uses for invoking actions. The advantage of this approach is that you can essentially remove the code-behind altogether as the PM complete encapsulates all of the behaviour for the view. This pattern is a very strong candidate for use in WPF applications and is also called Model-View-ViewModel.

     

    Hope this helps

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:41 PM
  • Greetings,

    N-tier application architecture provides a model for developers to create a flexible and reusable application. By breaking up an application into tiers, developers only have to modify or add a specific layer, rather than have to rewrite the entire application over. There should be a presentation tier, a business or data access tier, and a data tier.

    The concepts of layer and tier are often used interchangeably. However, one fairly common point of view is that there is indeed a difference, and that a layer is a logical structuring mechanism for the elements that make up the software solution, while a tier is a physical structuring mechanism for the system infrastructure.

    'Three-tier'  is a client-server architecture in which the user interface, functional process logic ("business rules"), computer data storage and data access are developed and maintained as independent modules, most often on separate platforms.

    The three-tier model is a software architecture and a software design pattern.

    Apart from the usual advantages of modular software with well defined interfaces, the three-tier architecture is intended to allow any of the three tiers to be upgraded or replaced independently as requirements or technology change. For example, a change of operating system in the presentation tier would only affect the user interface code.

    Typically, the user interface runs on a desktop PC or workstation and uses a standard graphical user interface, functional process logic may consist of one or more separate modules running on a workstation or application server, and an RDBMS on a database server or mainframe contains the computer data storage logic. The middle tier may be multi-tiered itself (in which case the overall architecture is called an "n-tier architecture").

    Three-tier architecture has the following three tiers:

    Presentation tier

        This is the topmost level of the application. The presentation tier displays information related to such services as browsing merchandise, purchasing, and shopping cart contents. It communicates with other tiers by outputting results to the browser/client tier and all other tiers in the network.
    Application tier (Business Logic/Logic Tier/Data Access Tier/Middle Tier)

        The logic tier is pulled out from the presentation tier and, as its own layer, it controls an application’s functionality by performing detailed processing.
    Data tier

        This tier consists of Database Servers. Here information is stored and retrieved. This tier keeps data neutral and independent from application servers or business logic. Giving data its own tier also improves scalability and performance.

    Comparison with the MVC architecture


    At first glance, the three tiers may seem similar to the MVC (Model View Controller) concept; however, topologically they are different. A fundamental rule in a three-tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middleware tier. Conceptually the three-tier architecture is linear. However, the MVC architecture is triangular: the View sends updates to the Controller, the Controller updates the Model, and the View gets updated directly from the Model.

    Hope this helps.

    Take Care

    PL

     


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:47 PM
  • Greetings,

    Layer (object-oriented design)

    In object-oriented design, a layer  is a group of classes that have the same set of link-time module dependencies  to other modules. In other words, a layer is a group of reusable components that are reusable  in similar circumstances. In programming languages, the layer distinction is often expressed as "import" dependencies between software modules.

    Layers are often arranged in a tree-form hierarchy, with dependency relationships as links between the layers. Dependency relationships between layers are often either inheritance, composition or aggregation relationships, but other kinds of dependencies can also be used.

    Layers is an architectural pattern described in many books, for example Pattern-Oriented Software Architecture

    Hope this helps

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:48 PM
  • Greetings

    Multilayered architecture

    A multilayered software architecture is using different layers for allocating the responsibilities of an application.

    There is also an architectural pattern that is named Layers and has been described in different publications, including the book Pattern-Oriented Software Architecture A System of Patterns. [1]

    The concepts of layer and tier are often used interchangeably. However, one fairly common point of view is that there is indeed a difference, and that a layer is a logical structuring mechanism for the elements that make up your software solution, while a tier is a physical structuring mechanism for the system infrastructure.

    Hope this helps

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:50 PM
  • Greetings

    Common layers in an information system logical architecture

    The following four layers are the most common layers in a logical multilayered architecture for an information system with an object-oriented design:

    •      User Interface Layer (aka View Layer, UI layer or Presentation layer)
    •      Application Layer (aka Service Layer or GRASP Controller Layer )
    •      Domain Layer (aka Business Layer, Business logic Layer or Model Layer)
    •      Infrastructure Layer (data access or other persistence, logging, network I/O e.g. sending emails, and other kind of technical services)


    Some common purposes of the above four layers are for example described in the book about domain-driven design 

    Sometimes there is no explicit distinction between the Domain Layer and the Application Layer, e.g. the Application Layer is considered as being a part of the Domain Layer. On the other hand, it is also possible to even further divide the Application/Domain Layers into more layers. For example, if the Model View Presenter pattern is used, then you can consider the Presenter Layer as being a layer between the User Interface Layer and the Application Layer.

    The Domain Layer can also use a Business Infrastructure Layer (aka low-level business services layer) between the Domain Layer and the Infrastructure Layer(s). That layer (BI) is very general and can be used in many different application domains, e.g. a CurrencyConverter.

    The Infrastructure Layer may be partitioned into different levels (high-level or low-level technical services). Though, it is not unusual that developers only consider the persistence (data access) and therefore only talk about the Persistence Layer or the Data Access Layer (instead of an Infrastructure Layer or Technical services Layer). In other words, the other kind of technical services are not always being explicitly thought of as being part of any particular layer.

    Regarding that all types are not always considered as belonging to one particular layer, according to the a relaxed layered system (as opposed to a strict layered system) can use so called "shared data definition modules" which are types not belonging in a particular layer.

    Hope this helps

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:54 PM
  • Greetings

    Common layers in an information system logical architecture

    The following four layers are the most common layers in a logical multilayered architecture for an information system with an object-oriented design:

    •      User Interface Layer (aka View Layer, UI layer or Presentation layer)
    •      Application Layer (aka Service Layer or GRASP Controller Layer )
    •      Domain Layer (aka Business Layer, Business logic Layer or Model Layer)
    •      Infrastructure Layer (data access or other persistence, logging, network I/O e.g. sending emails, and other kind of technical services)


    Some common purposes of the above four layers are for example described in the book about domain-driven design 

    Sometimes there is no explicit distinction between the Domain Layer and the Application Layer, e.g. the Application Layer is considered as being a part of the Domain Layer. On the other hand, it is also possible to even further divide the Application/Domain Layers into more layers. For example, if the Model View Presenter pattern is used, then you can consider the Presenter Layer as being a layer between the User Interface Layer and the Application Layer.

    The Domain Layer can also use a Business Infrastructure Layer (aka low-level business services layer) between the Domain Layer and the Infrastructure Layer(s). That layer (BI) is very general and can be used in many different application domains, e.g. a CurrencyConverter.

    The Infrastructure Layer may be partitioned into different levels (high-level or low-level technical services). Though, it is not unusual that developers only consider the persistence (data access) and therefore only talk about the Persistence Layer or the Data Access Layer (instead of an Infrastructure Layer or Technical services Layer). In other words, the other kind of technical services are not always being explicitly thought of as being part of any particular layer.

    Regarding that all types are not always considered as belonging to one particular layer, according to the a relaxed layered system (as opposed to a strict layered system) can use so called "shared data definition modules" which are types not belonging in a particular layer.

    Hope this helps

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:54 PM
  • Greetings


    What’s the difference between “Layers” and “Tiers”?

    logical layers are merely a way of organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model. But when we’re talking about layers, we’re only talking about logical organization of code. In no way is it implied that these layers might run on different computers or in different processes on a single computer or even in a single process on a single computer. All we are doing is discussing a way of organizing a code into a set of layers defined by specific function.

    Physical tiers however, are only about where the code runs. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.

    Hope this helps.

    Take Care

    PL

     


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:56 PM
  • Greetings

    Kindly go through the link which is given below

    Design Patterns: Solidify Your C# Application Architecture with Design Patterns
    http://msdn.microsoft.com/en-us/magazine/cc301852.aspx

    Hope this helps.

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 3:59 PM
  • Greetings

    What are advantages and disadvantages of Design patterns?

    Benefits:

    1. enable large scale reuse of S/W
    2. Helps in improve developer communication
    3. capture expert knowledge and design trade-offs and make
    expertise widely available

    Drawbacks:


    1.Do not lead to direct code reuse
    2. Complex in nature
    3. they are deceptivrly simple
    4. they are validated by experince and discussion

    Hope this helps

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 4:02 PM
  • Greetings,

    Kindly go through the example where a singleton design pattern is implemented. The link is very important.

    Implementing Singleton in C#
    http://msdn.microsoft.com/en-us/library/ms998558.aspx

    Hope this helps.

    Take Care

    PL


    Helping People To Solve Technical Problems
    Tuesday, April 13, 2010 4:05 PM
  • Hi Devasena,

    Design Patterns are well known patterns for solving technical problems in a way that has proven itself many times and about which you can communicate about. In that sense, the original Design Patterns as identified by Eric Gamma et al are not related to any particular layer. Martin Fowler however, has identified some more domain-specific patterns that are essentially variants of the technical patterns and are targetted at building architectures. You can read more about that here.

    The original guidelines by Gamma was to consider patterns when doing a big upfront design, but since then they have shifted their ideas to working towards patterns. So if you're building a system and use something like Evolutionary Design, every time you refactor your code and you find something that resembleds a pattern, consider replacing it with the actual pattern implementation. It really helps communicate your design and your ideas. Nevertheless, be carefull not to start seeing patterns as a goal, but use them as a means to an end.

    Hope this helps,

    • Marked as answer by Devasena_ace Thursday, April 15, 2010 7:58 AM
    Tuesday, April 13, 2010 4:29 PM
  • Looks like somebody is copying and pasting a lot...:-(
    Tuesday, April 13, 2010 6:27 PM
  • Thanks for the suggestions.

     

    Devasena


    Ace
    Wednesday, April 14, 2010 1:25 PM