2

I am tasked with testing several versions of a RestAPI. I thought of two ways to contain the set of valid rest calls. In the first case, I would have RestUrlFactory which contains a method that corresponds to each rest call. For example, I would have the methods:

public RestURL Version_1_1_PRODUCTS_GET();
public RestURL Version_1_1_PRODUCTS_PUT();
public RestURL Version_1_2_PRODUCTS_PRODUCT(int productId);
...etc

Alternatively, I figured I can have the RestUrlFactory contain an enumeration for each API Version. In which case, I would have an enum field for each rest call.

enum Version_1_1 implements RestUrl
{
    PRODUCTS_GET("/products", "GET"),
    PRODUCTS_PUT("TestProduct", "PUT"),
    ...
}

Or something of that nature. I think the latter option (using enums) is much cleaner. However, my question is if it is also good OOP Practice, and is it better in terms of performance? I figure using enumerations will result in the factory class taking up much less space.

4

1 回答 1

4

If people consuming this API are going to be making calls over HTTP, that is going to vastly outweigh any performance considerations here. Don't worry about performance: that will be premature optimization.

Using method signatures seems to me like it would give users the easiest API to use, since it provides type-safety and a very specific argument signature. I'd go with that.

于 2013-10-04T17:11:34.500 回答