My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
I'm writing a Client of FooServer which is reliant upon a rather clunky library whose functionality I'd like to encapsulate in a wrapper library to make the usage less clunky.

My first thought is to choose FooServer as the name of what will likely be the most used class in the library. That way, when I want to get some property of the server or tell it to perform some action I can do something like:

FooServer foo = FooServer.findById(12);
string property =;

That seems innocent enough. But my fear is that by calling the class FooServer, it may violate the principle of least surprise because it does not fully implement a Foo server, nor would it be of use in implementing a Foo server.

I also dislike tagging it with "Wrapper" or something of the sort, because reading that in the client code doesn't seem right either.

I know I'm probably over-thinking it, but names are important to me, because they are the start of clean, readable code that does what it says and says what it does. So that's why I come to you, dear reader.

What would you name the class?

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!

Leave a comment

Hi Sammy, what about calling it a FooAdapter?

Posted by Kevan Stannard on Feb 27, 2011 at 04:44 AM UTC - 5 hrs

I asked myself the same thing when I wrote the Apify gem, which includes classes for both server and client implementations. I ended up calling the client class Apify::Client and I'm quite happy with it.

I would always suffix the client class with something like "Client", "Connection" or "Remote", because this describes the class best. Nobody is helped when you pretend the connection is the server, and might even be confused by the name. Also you might eventually have some connection-related methods in that class (like timeout or proxy settings) and the abstraction falls apart completely.

Posted by Henning Koch on Feb 27, 2011 at 06:25 AM UTC - 5 hrs

@Kevan - I hadn't thought about it in those terms, but I suppose it is an Adapter or maybe Facade in terms of the GoF design patterns catalogue. I'll think about it some more.

@Henning: I agree with the client bit, and I'm glad you mentioned it because now that I think about it, I wonder if what I've written is more along the lines of a client. I'll have to ponder it a bit as well, but certainly it is wrapping actions and properties of the server.

The original clunky library actually interfaces with several types of servers: FooServer, BarServer, BazServer for instance. So I wonder if it would make more sense for me (and remove the naming strangeness) to go through 2 layers of abstraction: one to be an adapter for the library, and one for the specialization of that into accessing a FooServer.

Posted by Sammy Larbi on Feb 28, 2011 at 12:12 PM UTC - 5 hrs

I don't think what you have described is a client as such, since it is providing the services of the FooServer to its own clients. If this were all on the web, then I *think* what you are writing is a sort of proxy. Proxies have methods the server doesn't have, for example, to refresh their caches. So it is therefore not a subclass or instance of the server. And if it will stand in for other servers, the analogy seems more apt. But I don't have the full picture, so maybe what I have written is Just Wrong.

Posted by hgs on Mar 29, 2011 at 08:05 AM UTC - 5 hrs

@hgs: That a good point, I hadn't thought of it like that, but it does seem an apt metaphor.

In that case though, would you *name* it FooProxy, or is it better that the client code should not realize or read as if it's utilizing a proxy?

Posted by Sammy Larbi on Mar 29, 2011 at 01:16 PM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)


Subcribe to this comment thread
Remember my details

Picture of me

.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and Cplusplus (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Agile Manifesto & Principles
Principles Of OOD
Ruby on Rails

RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner