2

Both classes below implement the same interface and are in fact intended to be interchangeable one for the other. Why is the second one not referred to as a "client" in the literature?

There are many references to service layers, repositories, etc.:

How essential is it to make a service layer?

https://www.asp.net/mvc/overview/older-versions-1/models-data/validating-with-a-service-layer-cs

https://stackoverflow.com/questions/133350/whats-the-difference-between-a-data-service-layer-and-a-data-access-layer

This is a WebAPI client. We see the same pattern with WCF client, etc.

namespace Application.WebAPIClient
{
    public class UsersClient : BaseClient, IUsersService
    {
        public async Task<int> SaveUser(User user)
        {
            string json = JsonConvert.SerializeObject(user);
            StringContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
            HttpResponseMessage msg = await httpClient.PostAsync("users/saveuser", content);
            return Convert.ToInt32(await msg.Content.ReadAsStringAsync());
        }
    }
}

Why is the following not a "LAN client" or some other kind of client? Often called Repository or Service but never client although it wraps a call to sqlClient just as the code above wraps a call to HttpClient.

namespace Application.Repository
{
    public class UsersRepository : BaseService, IUsersService
    {
        // ...

        public async Task<int> SaveUser(User user)
        {
            db.Users.Add(user);
            await db.SaveChangesAsync();
            return user.ID;
        }
    }
}
  • 1
    This terminology has evolved over time from different perspectives, I wouldn't get too hung up over it. – cdkMoose Jan 6 '17 at 21:36
  • 1
    @cdkMoose Most correct answer thus far I think LOL. But I'm writing a wrapper class that returns a WCF or WebAPI or LAN client based on connectivity and it just looks weird to return new Repository() when I want a LAN client. And we don't even have a name for "LAN clients". It's something I made up. But we have a name for WCF clients, and REST clients and every other client. – Sam Jan 7 '17 at 16:58
7

Technically it is a client. Any class, method or interface that makes use of some other class, method or interface is a client.

However, this being the English language, we tend to use terms like this only where they are most useful. Hence, the word "client" in the context of data processing systems most commonly used to mean the end user and the software that he uses.

Imagine using the words "client" and "server" for every class or method you've ever written, and you'll quickly see how ridiculous this idea becomes.

  • Thank you Robert. Yes of course its a client. But we dont seem to mind including "client" in our REST clients, WCF clients, WebAPI clients. We have a layer for them. But the layer for the "LAN client" or whatever it is is called "Repository" or "Service" or "Business Logic". – Sam Jan 6 '17 at 16:39
  • The REST client is tied directly to the user's software, and computers can also be "users." – Robert Harvey Jan 6 '17 at 17:00
3

Because things are named according to their external appearances, not by their squishy insides.

The rest of your application needs a repository. It doesn't matter if that repository is or uses a client to do its work. It just needs to act like a repository.

  • IUsersService x = new (either one of the above). Looks the same to me. – Sam Jan 6 '17 at 16:40
  • 1
    If I actually write it out it makes more sense: IUsersService client = new UsersRepository(); - or - IUsersService client = new WebAPIClient(); First line is just visually weird. Why are we calling a repository a client? – Sam Jan 6 '17 at 16:47
1

The first example is code concerned about network communication. Serialization, de-serialization, encoding and URLs are for the purpose of communicating over the network.

In the second example, none of the code is concerned about network communication. It is concerned about persisting data. It might use some network communication under the hood, but it is not exposed.

Technically any code or component calling some other code or system can be called a client, but usually therm is used for a code or component where its primary purpose is communicating with some other system.

1

Client is a physical concept. Layer is a logical concept.

A DAL is not a client of the database. In fact it doesn't talk to the database at all. It is typically integrated with an ODBC client or some other data access technology located on the same physical machine. Note that the data access library IS in fact referred to as a client (example); this is appropriate because it communicates with something that is physically separated and on a different server.

  • The question is "Why is code that wraps...". Did you mean "Tier is a physical concept"? – Sam Jan 7 '17 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.