Importance of Programming with interfaces in API/Library Development

Importance of Programming with interfaces in API/Library Development

Let’s try to understand using a use case:

Use case : Suppose you work in a Product Development Company and you are requested to design a Cruise Controller class that will have adaptive speed control. Assume you have the below criteria:

a)???? You don’t know what type of vehicle you will need to control, it will be based on what type of customer shows interest of the cruise controller.

b)??? You will be provided Utility functions that can detect traffic/objects using sensors and analyze images. It tells you the estimate of the objects distance from your vehicle so that you know whether to increase/decrease speed or maintain the current speed or brake.

What are your design thoughts?

a)???? Since you don’t know what type of vehicles you will be provided, you can think of writing an abstract class and tell your clients to extend that class and implement their own speed functions. (Programming with abstractions)

?

Is it convenient to your client?


Programming to Abstraction
Programming to Abstractions

b) Better to write an interface and tell your clients that they should implement the Interface and can inject to your Cruise Controller class. ?(Programming with interfaces)


Programming to Interfaces

In that way, you can design API/Library even without knowing who will be using it.



code demonstration: Programming with interfaces

Question ?

What other SOLID principal implementation you can see in my code?


MD Fakrul Islam

Backend Engineering | Backend Design | Microservice| Observability | Big Data | Data Engineering | DevOps

4 个月

Insightful, well written

要查看或添加评论,请登录

Mohammad Iqbal的更多文章

社区洞察

其他会员也浏览了