界面和设计模式有什么区别?

What's the difference between an interface and a design pattern?

我很难知道什么时候是接口或设计模式。例如什么是观察者 - 可观察的?什么是 MVC?

我不太明白你的困惑。接口只是一组方法 class 实现它,'promises' 实现。模式的定义可能有所不同,这是我在网上找到的:

Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time.

根据你给出的这个例子,我的理解是 Observable 将是一个接口,每个想要具有 "observability" 特征的对象都应该实现。另一边:

The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.

这里的关键点是:通常通过调用他们的方法之一。 "dependents" 列表中的每个对象都需要实现 Observable 接口,以确保它具有 Observer 将调用的所需方法,无论它是什么类型的对象。通过定义一个具有上述方法的接口,你可以保证不同的classes会提供他们自己的方法实现,这在调用方法的地方并不重要。重要的是方法 存在

我希望我在某种程度上有所帮助和清晰。