Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracted Interface naming conventions

I'm currently refactoring some code to make it more testable. Specifically, I am extracting the interface of several classes to allow easy creation of test doubles.

I'd like to keep the public interface the same to this code, naming the interface after the original class.

However this leaves me with the problem of what to call the original class.

I'm using C++.

If my interface is:

class ServiceClient;

What should I call the contrete, I've come up with a few options that I'm not convinced by:

class ConcreteServiceClient;
class ServiceClientImpl;
class StandardServiceClient;
class BasicServiceClient;

What conventions do people use?

like image 855
Dave Hillier Avatar asked Jun 09 '09 14:06

Dave Hillier


People also ask

What naming convention should be used for method names?

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters.

What are the three java naming convention?

Interface Name: Should start with uppercase letter and be an adjective e.g. Runnable, Remote, ActionListener etc. Method Name: Should start with lowercase letter and be a verb e.g. actionPerformed(), main(), print(), println() etc. Package Name: Should be in lowercase letter e.g. java, lang, sql, util etc.


2 Answers

I would change the name of the interface class.

class ServiceClientInterface {};

Then place the concrete implementations in seprate namespaces:

namespace MyService
{
    class Client: public  ServiceClientInterface {};
}

namespace MyServiceTest
{
    class TestClient: public ServiceClientInterface {};
}

Or something completely different.
PS. I am into full names. I don;t like the the short 'I' is interface thing. Your taste may vary.

like image 162
Martin York Avatar answered Oct 14 '22 07:10

Martin York


Normally, I reserve "Impl" for the pimpl idiom. I use a full "Interface" on abstract base classes. For concrete implementations, drop the Interface and prefix with what specialization this is:

class ServiceClientInterface {
   // some pure virtual methods
};


class XMLServiceClient {
   // Or whatever "service" it is
};

class TestServiceClient {
   // some well defined
};
like image 22
Todd Gardner Avatar answered Oct 14 '22 06:10

Todd Gardner