This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.