"Programing to an an interface, not an importation"

xiaoxiao2021-03-06  42

Ashwin Jayaprakash Wrote in

Towards bug-free code:

One of the fundamental constructs of an object-oriented programming language is an interface. As you might already know, an interface represents a set of contracts or basic behavior that allows the developer to switch the implementation without having to make changes to the code again and Again.

A conscientious programmer will have a handful of interfaces in his program to ensure that the program is not too tightly coupled. An overzealous or novice programmer will be indiscriminate in creating too many interfaces and will still have packages that are neither stable nor easily extensible.

A line of code such as MyInterface intf = new MyInterfaceImpl () has little meaning, as the programmer has already decided that the implementation of MyInterface is MyInterfaceImpl right away To a mature programmer, the solution seems obvious:. Use a factory pattern.

Do you know how difficult? Is it difficult to know?

This code is not still in my program, and even the so-called Factory Method does not return a contRete class?

Programming to an interface, is not as simple as I used to think.

The road is still very long ....

转载请注明原文地址:https://www.9cbs.com/read-63124.html

New Post(0)