DEV Community

Discussion on: What is the purpose of an interface?

Collapse
 
nikolaias profile image
Nik Gil

Looks good, just had a few notes to make.

  1. I don't think it's that mandatory that the consumer of the interface doesn't know the implementation. It just shouldn't care. It seems that a method A takes in a string and parses it to a date. How it does it, the person doesn't care, all they care is the specification that's agreed by the interface (for example if the interface for some reason said that in invalid date defaults to 1, Jan, 1970 instead of null, the inementer must have that happen while the consumer just knows that this is the intended behaviour).

  2. For testing, we use fixtures to create some template objects, and only services are mocked (like something that would connect to an external service, which I think you mentioned, I'm just a little confused on whether the email is being mocked or the email service). One other thing I'd add is that sometimes we do this to encapsulate final methods and classes, for mocking purposes. Had this issue with Java recently where I couldn't mock some parts because the class was final in the Java spec so added an interface wrapper around the object to be able to mock the methods. A bit roundabout but c'est la vie.

  3. One thing that always makes its way in is abstract class vs interface. Like when does interface fit the agenda better than abstract class?