7

Say I have a class that implements multiple interfaces. I pass the same instance around using a different interface, depending on what the consumer is interested in.

I am trying to remember what this is called. I know there is a fancy name for it - I thought it was "interface partitioning", but I'm not finding any hits. The official name and perhaps a link to a site explaining what it is would be handy.

In case I haven't explained myself well enough, here is a real world example. I have a class, call it ContextManager, that is responsible for providing access to configuration settings, session variables, user information and other utilities. Instead of passing the object around as a ContextManager, I might pass it around as an IConfigurationManager in one spot and as a IUserManager in another. This prevents the client from accessing things they shouldn't care about and allows me to reuse code within the class.

I just want to know what it is called?

8
  • You're not thinking of polymorphism are you?
    – paul
    Mar 28, 2013 at 19:38
  • 1
    @paul No. I was sure there was a term specifically for splitting a class out into multiple interfaces for the purpose of limiting how other classes could use it. Mar 28, 2013 at 19:44
  • Are you talking about multiple inheritance?
    – markyd13
    Mar 28, 2013 at 19:52
  • 4
    This sounds like it might be related to the Interface Segregation Principle - maybe this will spark your memory.
    – Nate W.
    Mar 28, 2013 at 21:35
  • 3
    It's called "a class that implements multiple interfaces." Not everything on the planet needs a fifty-cent word.
    – Blrfl
    Mar 29, 2013 at 14:56

1 Answer 1

10

You're describing the facet pattern, which is used to restrict an interface to obtain a smaller interface that provides less authority. Inheriting multiple interfaces is one common way to implement this pattern.

This is related, but not identical, to the Interface Segregation Principle, which is the 'I' in SOLID. That principle states that no client should be forced to depend on methods it does not use. The facet pattern is a way to adapt that principle to a large class. However, there are other more common ways to follow the interface segregation principle, such as creating smaller classes.

4
  • I'm struggling to accept your answer. @shakedown's answer is actually what I was looking for but I am not seeing a distinction. Mar 28, 2013 at 22:07
  • @TravisParks: I believe the distinction between the Facet Pattern and the ISP is the former has a god interface and the latter doesn't.
    – Nate W.
    Mar 28, 2013 at 23:49
  • @shakedown Agreed. I have a hard time believing one of the SOLID principles would involve God classes. Mar 29, 2013 at 0:28
  • 1
    @Travis, since Shakedown apparently declined to create his own answer, I have incorporated his comment into mine. Mar 29, 2013 at 14:45

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.