I am the designer of an interface IModel, which will be used by the implementer of a the controller (MVC). The interface contains funcA(). Another programmer needs to implement a specific class for the IModel.

I want to direct the implementation of funcA() to use another function, funcB(). This forces some functionality of the specific model class to be transparent. For example, the interface contains openFile(), but the specific class must contain the transparent functionality of encrypting the file.

What is better?

  1. Defining two interfaces: I1 for the controller side, and another one, I2, for those who implement the model class, where I2 extends I1.
  2. My own implementation of an abstract class like AbsModel which implements Imodel and contains abstract functions.

1 Answer 1


Abstractly: You cannot control how anyone implements your Interface.
All you can do is force them to have a method that matches your Interface, so that you can use their class - whatever it does - in place of any other class that implements your Interface.

If you want to ensure the class has a method to decrypt the file - whatever file that might be - then you have to add it to your Interface, but then you run the risk that whilst the function must be there, it doesn't have to actually do anything (classic example: the DataSet's Binary Serializer that simply wraps the output from the Text Serializer, unmodified, into a Byte array!) or it might do something completely different.

There are many, many encryption schemes - which one is your Implementer supposed to use?

I think you should add methods to the Interface for encrypting/ decrypting your files, but also an additional, concrete Class that implements this capability; using this Dependency Injection method, any Implementer of your Interface can instantiate your decrypting Class and pass it to their own method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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