aspose file tools*
The moose likes Java in General and the fly likes N tier architecture Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "N tier architecture" Watch "N tier architecture" New topic
Author

N tier architecture

RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hi
I am newbie to programming
I am developing n-tier application in java

Following is my app structure

In Controller package
UserController
AdminController

In Service Package
UserService
AdminService

In Dao Pacakge
UserDao
MessagesDao

Now in userService i have method named
getUserMessages(User user);

In AdminController i need the same method
Do i rewrite the same method or i should use userservice in AdminController

Or should i make MessageService instead of AdminService


OR should i go for three service Classess
AdminService
UserService
CommonService

And Admin and UserService extends CommonService

Thanks In Advance
Ramandeep Singh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
What are you planning to use? I think you would have to provide a lot more detail before we could answer that question.
Aditya Jha
Ranch Hand

Joined: Aug 25, 2003
Posts: 227

Although your post invites a big design discussion, for which a lot of information is required, I'll still try to answer some of your questions.

If there is any unfamiliar jargon in my answers, please excuse and try to Google the terms.

RamandeepS Singh wrote:Hi
I am newbie to programming
I am developing n-tier application in java

I don't mean to be rude, but it seems that you are missing a few steps here. Before starting to code an n-tier application, you need to design it, and before you can design it, you need to know enough about separation of tiers and the reason they exist in an enterprise application. It would also help to know about the choice of technologies/frameworks you can use on each tier.

Ask yourself/your team - WHY am I doing this? WHAT will I achieve with this? HOW should I design this in an efficient manner, and finally, WITH WHAT technologies/frameworks should I be implementing this.

RamandeepS Singh wrote:In AdminController i need the same method
Do i rewrite the same method or i should use userservice in AdminController

Usually, a web component acts as a facade for one or more business methods. In other words, usually a Controller may have similar methods as defined in a Service component. However, the implementation and the exact semantics will be different and will be more suited to web requirements. For example, your controller method may include HttpServletRequest and HttpServletResponse as parameters, whereas your Service methods will never have them, and would rather talk in terms of model/domain objects.
While you're at it, you also need to think about the mechanism through which a Controller will communicate with a Service instance. If you want to reduce coupling between these classes (always a good idea), you can take advantage of Java interfaces and Spring's dependency injection.

RamandeepS Singh wrote:Or should i make MessageService instead of AdminService

OR should i go for three service Classess
AdminService
UserService
CommonService

And Admin and UserService extends CommonService

These are strictly design questions, which should not be answered without knowing the requirements. One word to guide you, though - think about Cohesiveness in your OO design.

Try to conceptualize the enterprise application in terms of design concerns to be resolved. That is the birthplace of tiers as a concept. You will find it much easier to think about responsibilities and design of components if you first appreciate the need for the different tiers and components in your application.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: N tier architecture