Sunday, November 4, 2012

n-tiered application



  • The J2EE platform is a multi-tiered system

A tier is a logical or functional partitioning of a system

Client tier represents Web browser, a Java or other application, Applet, WAP phone etc. The client tier makes requests to the Web server who will be serving the request by either returning static content if it is present in the Web server or forwards the request to either Servlet or JSP in the application server for either static or dynamic content.

Presentation tier encapsulates the presentation logic required to serve clients. A Servlet or JSP in the presentation tier intercepts client requests, manages logons, sessions, accesses the business services, and finally constructs a response, which gets delivered to client.

Business tier provides the business services. This tier contains the business logic and the business data. All the business logic is centralized into this tier as opposed to 2-tier systems where the business logic is scattered between the front end and the backend. The benefit of having a centralized business tier is that same business logic can support different types of clients like browser, WAP, other stand-alone applications etc.

Integration tier is responsible for communicating with external resources such as databases, legacy systems, ERP systems, messaging systems like MQSeries etc. The components in this tier use JDBC, JMS, J2EE Connector Architecture (JCA) and some proprietary middleware to access the resource tier.

Resource tier is the external resource such as a database, ERP system, Mainframe system etc responsible for storing the data. This tier is also known as Data Tier or EIS (Enterprise Information System) Tier.



The advantages of a 3-tiered or n-tiered application:
3-tier or multi-tier architectures force separation among presentation logic, business logic and database logic

Manageability: Each tier can be monitored, tuned and upgraded independently and different people can have clearly defined responsibilities.

·         Scalability: More hardware can be added and allows clustering (i.e. horizontal scaling).

·         Maintainability: Changes and upgrades can be performed without affecting other components.

·         Availability: Clustering and load balancing can provide availability.

·         Extensibility: Additional features can be easily added.
http://allu.wordpress.com/2007/08/18/j2ee-3-tier-or-n-tier-architecture/



  • In software engineering, multi-tier architecture (often referred to as n-tier architecture) is a client–server architecture in which presentation, application processing, and data management functions are logically separated. For example, an application that uses middleware to service data requests between a user and a database employs multi-tier architecture. The most widespread use of multi-tier architecture is the three-tier architecture.

http://en.wikipedia.org/wiki/Multitier_architecture



  • Using J2EE to develop n-tier applications involves breaking apart the different layers in the two-tier architecture into multiple tiers. An n-tier application could provide separate layers for each of the following services:


    Presentation: In a typical Web application, a browser running on the client machine handles presentation.
    Dynamically generated presentation: Although a browser could handle some dynamically generated presentation, for the widest support of different browsers much of the action should be done on the Web server using JSPs, servlets, or XML (Extensible Markup Language) and XSL (Extensible Stylesheet Language).
    Business logic: Business logic is best implemented in Session EJBs (described later).
    Data access: Data access is best implemented in Entity EJBs (described later) and using JDBC.
    Backend system integration: Integration with backend systems may use a variety of technologies. The best choice will depend upon the exact nature of the backend system.
http://www.javaworld.com/jw-12-2000/jw-1201-weblogic.html

Proxy Pattern



  • The Proxy Pattern

Intent
Provide a surrogate or placeholder for another object to control access to it

A proxy is
› a person authorized to act for another person
› an agent or substitute
› the authority to act for another

There are situations in which a client does not or can not reference an
object directly, but wants to still interact with the object

A proxy object can act as the intermediary between the client and the target
object

http://userpages.umbc.edu/~tarr/dp/lectures/Proxy.pdf



  • Intent

    Provide a surrogate or placeholder for another object to control access to it.
    Use an extra level of indirection to support distributed, controlled, or intelligent access.
    Add a wrapper and delegation to protect the real component from undue complexity.

Problem

You need to support resource-hungry objects, and you do not want to instantiate such objects unless and until they are actually requested by the client.

Example

The Proxy provides a surrogate or place holder to provide access to an object. A check or bank draft is a proxy for funds in an account. A check can be used in place of cash for making purchases and ultimately controls access to cash in the issuer’s account.

Rules of thumb

    Adapter provides a different interface to its subject. Proxy provides the same interface. Decorator provides an enhanced interface.
    Decorator and Proxy have different purposes but similar structures. Both describe how to provide a level of indirection to another object, and the implementations keep a reference to the object to which they forward requests.
 
http://sourcemaking.com/design_patterns/proxy



  • Proxy pattern

A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate.
http://en.wikipedia.org/wiki/Proxy_pattern

flyweight pattern



Basit nesneler olusturmak istiyorsunuz ve bu nesnelerin bazi
veri degerleri farklidir. Nesnelerdem çok fazla
olusturdugunuzda bellek fazla kullanilacaksa, nesnelerden 1
tane olusturup, farkli verileri bu nesneye metot parametresi
olarak göndermek daha iyi olacaktir.

Bu kullanim flyweight sablonudur.

Örnegin; bir kelime islemci uygulamasindaki her harf için bir
nesne olusturmaktansa harfin bir kopyasi olusturulur ve
kullanilacagi yerlerde bu kopyanin referansi kullanilir.

http://members.comu.edu.tr/msahin/courses/ust_duzey_files/patterns/flyweight.pdf

Abstract Factory pattern


Abstract Factory pattern

Intent

Provide an interface for creating families of related or dependent objects
without specifying their concrete classes.

The Abstract Factory pattern is very similar to the Factory Method pattern.
One difference between the two is that with the Abstract Factory pattern, a
class delegates the responsibility of object instantiation to another object
via composition whereas the Factory Method pattern uses inheritance and
relies on a subclass to handle the desired object instantiation.

Actually, the delegated object frequently uses factory methods to perform
the instantiation


Applicability
Use the Abstract Factory pattern in any of the following situations:

A system should be independent of how its products are created,
composed, and represented
class can't anticipate the class of objects it must create
A system must use just one of a set of families of products
A family of related product objects is designed to be used together, and you
need to enforce this constrain

http://userpages.umbc.edu/~tarr/dp/lectures/Factory.pdf