Interface-Segregation Principle and SmartFoxClient

We are using Smartfox as server technology for our new project and we also used it for our previous project and, what I found a bit annoying is that Smartfox provides an AS3 API that, in my opinion, is a bit messy.

I’m not saying that it’s wrong or it doesn’t work, I’m just thinking that we can improve it by introducing different interfaces for its different sections/responsibilities, so to drive developers to develop towards Interfaces and to make the API clearer.

So what I would like to do is to apply the Interface-Segregation Principle and break down the SmartfoxClient API.

SmartfoxClient is responsible of connecting to the server AND manage users AND manage rooms AND menage messages… for me there are too may ANDs, and that smells.

What I suggest is to create different Interfaces for the different responsibilities of SmartfoxClient as follow:

  • SmartfoxClientConfig : responsible of the configuration of the client
  • SmartfoxClientConnection : responsible of all the connection related functionalities
  • SmartfoxClientUser : responsible of all the user related functionalities
  • SmartfoxClientRoom : responsible of all the room related functionalities
  • SmartfoxClientBuddyList : responsible of all the buddy list related functionalities
  • SmartfoxClientMessaging : responsible of all the messaging related functionalities

then make SmartfoxClient.as implement all of the above. (or create a wrapper for it which implements all of the above)

By doing that you can then create your smartfox connection logics focusing only on SmartfoxClientConnection interface, if you are dealing with the user management you just use  SmartfoxClientUser interface, etc.

I think this approach will make your code more readable and also will make SmartfoxClient API easier to use and understand.

I’ll give it a go and see what I come up with.

UPDATE

I ended up creating a new Class for each responsibility with its own interface, and a Wrapper Class which is composite with a reference of the SmartFoxClient and a reference of each “responsibility class”.
The Wrapper will then inject the SmartFoxClient reference in each “responsibility class” and expose a simple API to retrieve the different interfaces (SmartfoxClientConfig, SmartfoxClientConnection, etc.).

This entry was posted in AS3, SmartfoxServer. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
blog comments powered by Disqus