api-design

Overloaded package-private method causes compilation failure - Is this a JLS oddity or javac bug?

I've come across an oddity of the JLS, or a JavaC bug (not sure which). Please read the following and provide an explanation, citing JLS passage or Sun Bug ID, as appropriate. Suppose I have a contrived project with code in three "modules" - API - defines the framework API - think Servlet API Impl - defines the API implementation - t...

Preferred way to convert from Lazy/Delay-loading to Eager-loading in an API?

I've been working on an API (which wraps a web-service of sorts) for a while now, and its just about feature complete. I initially designed this API to be lazy/delay-loaded throughout; which makes perfect sense if you're only interested in a small subset of the available data given the latency inherent in consuming a web-service. Howev...

Minimal API v. Convenience

I am trying to design the interface that will be used internally for my application. Following Google's example, I strive to reduce public API clutter. However, there are some convenience methods that are defined in terms of the minimal methods. What factors should I consider as I seek a balance between convenience and tidiness? Google ...

API development, one gateway page?

Im currently developing an API, and one thing that I decided was to have one gateway.cfm page that the client sends the request to with a sig for verification and etc, and the gateway processes the request and sends the result back by invoking the components needed. For example gateway.cfm?component=getBooks&sig=232345343 will call th...

API design - allocate output?

Is it a good idea for C API functions to allocate their output, or to have the user specify the output buffer? For example: BOOL GetString( PWSTR *String ); ... PWSTR string; GetString(&string); Free(string); vs BOOL GetString( PWSTR Buffer, ULONG BufferSize, PULONG RequiredBufferSize ); ... // A lot more code...

Does anyone design api or library code in this way?

I was reading up some things about how to design a library or API well, and stumbled across Joshua Bloch's great talk at Google Tech Talks. Now although I am nowhere near a professional API developer, I think programming a bunch of classes/functions is a similar, although much scaled-down version of the same thing - clear-cut separation ...

Framework Design Guidelines for other languages

In .NET, Framework Design Guidelines is the official standard for how APIs are supposed to be designed. Do other languages and similar books and, if so, what are they called. ...

static vs non-static method for immutable class

Given the class definition below. How would one go about deciding whether the stub methods should be static or non-static? class Point { private final int x; private final int y; public Point(int x, int y) { this.x = x; this.y = y; } // Should the methods add(), subtract() and inverseOf() be non-sta...

Is jQuery 1.4's new behavior a bad design choice?

This is a bit of a rant, but also a very serous question. jQuery has changed ajax param serialization as follows: jQuery 1.4 adds support for nested param serialization in jQuery.param, using the approach popularized by PHP, and supported by Ruby on Rails. For instance, {foo: ["bar", "baz"]} will be serialized as “foo[]=bar&foo[]=baz...

Is it acceptable to return unmodifiableList or should I return array?

I have method List<Foo> getFoos () which gets the data from remote server and returns it. Of course, user shouldn't change number of items of the list because he'll get data not synchronized with data on the server (and if he want change number of items he has special methods like addFoo ()). First approach was to return array and cha...

How to init class with unknown number of String params?

I'm working on API which should provide simple access to number of remote web-service based resources. Some of these remote resources requires special parameters to be passed before interaction. For example, one of them requires pair of developer's keys to be passed, another requires pair of keys and unique identifier. Third one does...

Why is JavaMail Transport.send() a static method?

I'm revising code I did not write that uses JavaMail, and having a little trouble understanding why the JavaMail API is designed the way it is. I have the feeling that if I understood, I could be doing a better job. We call: transport = session.getTransport("smtp"); transport.connect(hostName, port, user, password); So why is Eclips...

Why do some APIs (like JCE, JSSE, etc) provide their configurable properties through singleton maps?

For example: Security.setProperty("ocsp.enable", "true"); And this is used only when a CertPathValidator is used. I see two options for imporement: again singleton, but with getter and setter for each property an object containing the properties relevant to the current context: CertPathValidator.setValidatorProperties(..) (it alread...

Array of structs or one struct with array for each of its properties

Hi, When designing an API, I may want to persist details (Eg of a process running) into my own custom struct. However, if I am going to do this for more than 1 process, meaning I need several structs, should I have an array of structs or one struct with an array for each of its properties (eg startTime, processName and other process pro...

Definition of coarsely grained/finely grained in architecture

Hi, When talking about APIs, the terms "coarsely grained" or "finely grained" are used a lot. What do these mean/are there any examples? Thanks ...

What name should have method which returns number of nested objects?

Suppose we have classes Gallery and Image. There can be many images in one gallery. Gallery should have some method which returns number of nested images. My suggestions: int getImagesCount (); int countImages (); int imagesCount (); I saw examples of each of these 3 suggestions in different APIs (of course with another noun or ev...

Suggest me a better name for an API method

Introduction: I'm working on API which provides access to Picasa, Flickr and some other image services. I have a class WebAlbum (it provides access to nested photos, albums if allowed, and some meta information). My API allows not only read albums but it also allows to create new albums. In general case in order to create new album AP...

Restrictive API (imposing limits on the client user)

Hi, I am writing an API and have come across the following pattern: My API will force the client user in what he/she writes. The code must test x number of sites on a portal by logging in/out with different credentials. I cannot rely on chance that another developer will write his/her own login code (and this is going to be common code...

Is this a good interface for persistent state?

I'm developing a game that maintains its information in a class called WorldState. Each GameObject in the world (trees, zombies, the player, health packs, etc) is composed of three objects: GameObjectController, GameObjectModel, and GameObjectView. (These classes may be extended if the GameObject requires additional functionality.) Worl...

Why eGet() in EMF returns Object rather than EObject?

I am working on some code using the EMF framework in Java, but it is really hard to use, e.g. I cannot implement OCL-like query API on top of EMF which would be type-safe. One of the reasons is that eGet() for a EStructuralFeature return just an Object, not EObject. So anything I would write must use much of null checking, type checking ...