Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, March 11, 2013

Breaking it down further (Application Tier)

As mentioned in my earlier posts, the logical tiers that make up "Application Architecture" are (in my mind) the Client Tier, Application Tier, and the Integration (or Data) Tier. Some of the application architecture tiers can be further broken down into logical layers.

As application designers/developers/architects, we are generally most concerned with the Application Tier, because that is where the bulk of most application logic and functionality reside (with the notable exception in the Web 2.0 world that is moving more and more presentation and business logic down to the client tier, but that is another matter).

Application Tier
For design purposes, the Application Tier can then be further broken down into into several discrete Application Layers, which provide a logical separation of concerns for our application.


As you can see, the application layers include:
  • Presentation Layer
  • Business Layer (Services and Objects)
  • Integration/Data Layer
Presentation Layer
The aptly named presentation layer is pretty much exactly what you would expect.  It is the presentation of the application to the user, delivered generally as a group of UI components as well as UI Process components.  It basically orchestrates the response to any application requests, which for web applications are generally HTTP requests originating from a browser (web service applications are a bit different in implementation, but similar in concept).

Depending on the nature of the application and the technologies in place, this layer can be delivered as a wide variety of components.  Regardless of the technologies used, one over-riding pattern that is generally considered the best approach for managing the interactions between UI and UIP components is the Model-View-Controller (MVC) pattern, whose responsibilities include:
  • receiving and handling user events, acting as the overall request "controller"
  • calling out to service classes to build the "model" data for the response
  • creating appropriate "view" responses and sending to the caller
An interesting point that is often overlooked is that the Presentation Layer is generally the only "stateful" layer within the application architecture (since it is responsible for managing the user sessions/state). Ideally, the Business and Integration/Data Layers of an application are "stateless" (to open up the possibility for re-use of these components by other clients/callers).

Business Layer
The business layer is where the 'guts' of the business logic is stored.  This is generally where the real functionality of the application is implemented.  Components in this layer are generally structured around real-world business concepts, and encapsulate the business logic (or business rules) for the application functionality being delivered.

Many times, these functions are broken down into more logical services (aka Business Services), and delivered through some sort of application facade, often referred to as a Service Interface.  Now, this doesn't necessarily mean that it uses Web Services, but that is one method for having a more technology-agnostic approach for developing business functionality and making it available to applications leveraging multiple technology stacks.

Similarly, there are often software components that represent their real-world counterparts that are often called the Business Objects (like Invoice, Employee, Customer, etc.).  These are generally just containers for managing related data and presenting it in a meaningful way.  While these objects often originate in the Business Layer, they can be used to pass the structured data between layers (to the Presentation Layer, for example).

Integration/Data Layer
The Integration Layer is the interface for the Business Layers to interact with any enterprise systems (including databases).  This is where the distinction between Layers and Tiers is most useful.  Most business applications are centered around delivering "data", which often resides in some sort of back-end repository, like a database (although there are many other possibilities, like ERP systems, LDAP trees, Web Services, etc.).  The components in the integration layer (or data layer) are responsible for exposing the data from these repositories to the business layer.

The Integration Layer is often implemented using Data Access Objects (DAO) for database access or Adapters for other enterprise integrations (Web Services, RSS, etc.).  Continuing the practice of separating design from implementation, one preferred approach here is to define an interface for the DAO, like StudentDao, and then provide an appropriately named implementation, like JdbcStudentDao (if JDBC based, could also be HibernateStudentDao).

As just mentioned, Object-Relational-Mapping tools (ORM) like Hibernate are another option for the Integration/Data Layer, but they can add a level of complexity that is not always required for business applications (particularly those that are "view-only").

Stored procedures are an interesting case., and can complicate the logical separation of layers and tiers.  While the stored procedures can often contain "business logic" that would be considered part of the Application Tier, the actual implementation (code) resides within the database itself - on the Data Tier.  This murkiness is generally undesirable, and as such I generally prefer to avoid stored procedures when possible.  There are cases when their use makes sense, but keep in mind that it can complicate your application architecture.




Saturday, February 23, 2013

Breaking it down further (Integration/Data Tier)

As mentioned in my earlier posts, the logical tiers that make up "Application Architecture" are (in my mind) the Client Tier, Application Tier, and the Integration (or Data) Tier. Some of the application architecture tiers can be further broken down into logical layers. The Integration/Data Tier generally doesn't fall into that category, so I'll just spend a little time talking about what I mean when I refer to the Data Tier (from now on, I'll generally refer to this as the "Data" tier, as that is what is most often used in business applications).

Integration/Data Tier
The Data Tier is generally responsible for managing the persistent application data. This data management typically includes:
  • Storage/retrieval of data
  • Managing updates to the data
  • Allowing simultaneous, or concurrent access (by more than one middle-tier process)
  • Providing security for, and ensuring the integrity of the data
In most business applications, these services are provided by a RDBMS. However, the Integration/Data Tier is used to refer to whatever back-end repository is being used as a persistence mechanism for the relevant application data (ERP system, image repository, web service, etc.).
Frequently (but not always), the database is separated physically onto its own tier. However, the performance of an application can suffer greatly if this physical separation from the application tier is too great. When planning the application, work with the appropriate teams (e.g., enterprise architecture, DBA, etc.) to determine the appropriate physical server location and configuration for your Data Tier - taking into account the Application Tier (which will be discussed next).

Saturday, February 16, 2013

Breaking it down further (Client Tier)

As mentioned in my earlier post, the logical tiers that make up "Application Architecture" are (in my mind) the Client Tier, Application Tier, and the Integration (or Data) Tier. Some of the application architecture tiers can be further broken down into logical layers (see my previous blog about how I differentiate between "tiers" and "layers"). Let's start with the Client Tier.

Client Tier
These days, the client tier generally maps to the browser, as is the case with any web application. When referring to "Client-Server" type applications where there is a separate application client program installed on the client machine, things are a little different (and there would be cases where it makes sense to break this down into logical layers), but in the web-world, the client is generally used only as a presentation vehicle for the application user.

The Web 2.0 model has complicated that a bit as well (with AJAX having the potential to move functionality/business logic to the Client Tier). This would be another case where it makes sense to break the tier down into additional logical layers. However, that is a topic for another day.

Thus, the Client Tier (for non-AJAX web applications) is generally responsible for:
  • Display of HTML resources
  • Issuing HTTP requests for resources,
  • Processes HTTP responses
Generally, this means that the Client Tier will be mainly interacting with the Application Tier, sending requests and receiving responses that are then rendered for the user. Pretty straightforward stuff here (except when you bring this whole "Web 2.0" thing and the AJAX that goes along with it).

Saturday, February 9, 2013

Application Architecture - Tiers or Layers?

While application architecture is complicated enough by itself, the ambiguity or multiple interpretations of words or concepts adds yet another wrinkle. One example of this that I've run into recently has to do with the separation of the logical and physical components within an application.

Most developers/architects will agree that there are (at least) 3 separations that are meaningful enough to warrant their own grouping:
  • Client "stuff"
  • Application "stuff"
  • Data "stuff"
But are these "layers" or "tiers"? There are a lot of people that use these terms interchangeably, and until somewhat recently, I did too. That changed while I was doing some online research to pull together documentation for a recent project.

I stumbled upon a couple of articles that made a differentiation between the two that I think makes a lot of sense (thanks to Pranshu Jain's Blog and the Guidance Share Wiki for their insight).
Physical separation versus logical separation is the distinction. If the layers are physically separated (or have the potential to be physically separated), then they can be referred to as tiers. Logical separation (particularly for design concerns) is indicative of architecture layers.

So, as mentioned above, most web applications have 3 tiers:











I plan to continue to use this distinction moving forward, because I think there are some places where it can really add value (which I will discuss in more detail within future blog entries).

Thursday, February 18, 2010

Annotations - Good, Bad, or Ugly?

In my workplace, we are currently in the process of moving towards JDK 1.5 (I know, we're not on the cutting edge of technology, with many apps still on JDK 1.4 and even 1.3).

As such, I am finally taking the time to dig into some of the newer Java features. Annotations are one item that was introduced with JDK 1.5 (or I guess its called Java 5 now) that I haven't made up my mind about yet.

Annotations, simply put, are a facility within Java for providing meta-data about code. From what I can tell so far, there are a couple different flavors (or uses) for this meta-data:
  • documentation (acting essentially as a form of structured comments within the source code)
  • compiler information (to provide a little clearer instructions to the compiler about how to handle the code - things like @Deprecated, @Override, @SuppressWarnings are all pretty clear in what they are telling the compiler)
  • specialized processing (I suspect that this will more likely be used by frameworks, etc.)
In fact, my main exposure to annotations so far are from the Spring documentation (can you tell that I'm a fan of Spring?) It seems to be a way to remove some of the restrictions based on naming conventions, as well as a means of simplifying the XML configuration files (which I admit can get cumbersome).

I can see some advantages for using annotations, but I can also see it getting easy to mix in environment specific or configuration information that really shouldn't be embedded in the code.

More to come on this topic, but to answer the question posed in the title of this blog, I suspect its going to be like many other technologies - has some benefits when used properly, but can be easily abused (or used for the wrong reason).

Friday, January 29, 2010

Learning Java? Look at Spring

For those that are learning Java, or those that want to improve their skills, I highly recommend learning about the Spring framework.

Initially, just using it will help enforce good design principles within your applications, but if you want to truly grow as a developer (and designer), you should dig into the details and understand the implementation of Spring. It applies good design principles consistently (like separating interface from implementation), and can be a good reference for understanding how to use design patterns. For example, JdbcTemplate is a classic use of the Template pattern (or Template Method, depending on who you ask).

In fact, the JDBCTemplate is probably the best place for those that are new to Spring to get started. It is a valuable addition to most applications that use JDBC, even if no other Spring services are utilized. It can be a straightforward introduction of Spring into an application (or even an organization). It really simplifies the use of JDBC by handling much of the common plumbing work that is required, and lets the developer focus on the business logic.

By understanding how these patterns are applied within Spring (and the the problems that they are solving), you will begin to recognize similar problems in the applications that you build - and apply the appropriate patterns to solve them.

Its as simple as starting with the javadoc to look at the class structure and hierarchy, but I would encourage you to go further and actually step through the running code in a debugger to be sure that you understand the call path - I have always found the debugger to be an invaluable resource when trying to understand code behavior.

Saturday, March 14, 2009

Good books for programmers

Clean Code: A Handbook of Agile Software Craftsmanship
Right now, I'm reading "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin.  This is a great book - a lot of tips that sound like common sense, but are often ignored (even by seasoned developers). This book does a nice job of codifying the best practices of some of the industry's best programmers.

Refactoring
Another book that is great for younger developers that are looking to grow their skills and improve the applications that they develop. "Refactoring: Improving the Design of Existing Code", by Martin Fowler talks about the process of gradually taking an application and improving it incrementally to "fix" the design (plenty of additional knowledge is gathered in the development process, so at some point a developer needs to go back and apply that to the design).

There are plenty of others:
  • Effective Java - Joshua Bloch (more good tips)
  • Practical Java - Peter Hagger (yet another collection of good practices)
  • Expert One-on-One J2EE Design and Development - Rod Johnson (a pre-curser to his work on the Spring Framework)
What else???