• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

N tier architecture

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you planning to use? I think you would have to provide a lot more detail before we could answer that question.
 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic