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 4 of 4

Thread: Managing different types of input

  1. #1
    Junior Member jbraque's Avatar
    Join Date
    May 2013
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Managing different types of input

    Hello,

    Suppose there is an API with a class that calculates the area of an arbitrary polygon.
    The API is going to be used from several programs. But every program has different objects to store the coordinates of a polygon.
    How can this API manage all the different inputs? For example programA stores the coordinates as ArrayList<Point2d> and programB stores them in a different structure.

    Thanks.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,699
    Thanks
    25
    Thanked 334 Times in 310 Posts

    Default Re: Managing different types of input

    If there are an infinite number of different inputs, the API cannot be responsible for managing that. A solution would be to force standardization from the program using this API.
    For example, create a class named Coordinate or something in the API and make the method accept an ArrayList<Coordinate>. Then make every program convert their list of objects into the a list of Coordinate objects before calling a method.
    Now, if all of the objects sent as input extend from a common parent class who has the functionality you need for the method, you can just accept an ArrayList<[some-parent-class]>, and no conversion would be necessary.
    You'll have to give us a better idea of how varied your inputs are if you want a better answer.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    jbraque (May 19th, 2014)

  4. #3
    Junior Member jbraque's Avatar
    Join Date
    May 2013
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Managing different types of input

    Thank you for your answer. The example is fictional, but i suppose each program would have different data structures, so the conversion you mentioned is logical.

  5. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    858
    Thanks
    0
    Thanked 158 Times in 141 Posts

    Default Re: Managing different types of input

    Just have an interface, for example Coordinate2D, which defines 2 methods: getX() and getY(). The user would only need to make his data structure implement this interface, or build a wrapper around it.

Similar Threads

  1. [SOLVED] Managing layout in JFrame
    By stewbond in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 26th, 2013, 08:52 AM
  2. Managing Http requests
    By maxitis in forum Java Networking
    Replies: 2
    Last Post: December 1st, 2012, 04:03 PM
  3. Help Managing Generated Data
    By PineAppleKing in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: October 16th, 2011, 05:06 PM
  4. Managing an embedded database
    By jstn455 in forum JDBC & Databases
    Replies: 1
    Last Post: April 24th, 2011, 11:06 AM
  5. problem in managing layout
    By namreen in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 26th, 2010, 01:52 AM