Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Project layout for web service

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Project layout for web service

    Hello,
    I am new to Java and I am trying to create my first web service. I am using Eclipse, Java and Axis2 to do so. I have the service up an running but now I want to ensure that my business logic and so on "lives" in the right place.

    I have created a new project, added a new package and to that a new class called MyService.java

    package pkg;
    public class MyService{
     
    	public MyService() {}
     
    	public String SayHello(String name){
    		return "Hello " + name;
    	}
     
    	public int CalcStuff(int first, int second){
    		return first + second;
    	}
    }

    And thats it. It works and I can call the web service from another application.
    Now I want to learn the proper way to do the above, assuming that it is incorrect. I think that I should change the MyService Class to not contain the "business logic" but instead have something like this:
    public class MyService {
     
    	public MyService() {}
     
    	public String SayHello(String name){
     
    		return Hello.getHello(name); //calls a class that has business logic
    	}
     
    	public int AddNumbers(int first, int second){
    		return Numbers.AddNumbers(first, second); //calls a class that has business logic
    	}
    }

    Is the second way better? Is there a third way that is way better? Or is the first way I did it ok?

    I know these are small methods, but I want to understand the way it should be before I start making actual web services.

    Thanks


  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Project layout for web service

    The second way is much better than the first way as it leaves the service class unchanged when we need to change the business logic. It s always better to keep the interface class(accessed directly by client) unchanged.

Similar Threads

  1. Is there a layout for this?
    By gkffjcs in forum AWT / Java Swing
    Replies: 2
    Last Post: September 27th, 2011, 09:15 AM
  2. Layout Manager
    By mDennis10 in forum AWT / Java Swing
    Replies: 4
    Last Post: September 3rd, 2011, 10:27 PM
  3. Replies: 1
    Last Post: April 14th, 2011, 07:50 AM
  4. Grid bag layout inside grid bag layout
    By kiddkoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2011, 08:07 AM
  5. Layout manager
    By kurt-hardy in forum AWT / Java Swing
    Replies: 3
    Last Post: January 19th, 2011, 10:25 AM