1

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.
jscs
8489 silver badges17 bronze badges
asked Aug 11, 2016 at 16:02

1 Answer 1

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.

answered Aug 12, 2016 at 11:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.