设计模式 - API [英] DESIGN PATTERNS - API

查看:83
本文介绍了设计模式 - API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在电子商务系统中出现类似情况,可以实施哪种模式:



存在客户和消息(通知)产品的变化如价格等。它是通知部分中的相关观察者模式。但我怀疑我应该使用Facade或Adapter设计模式,同时通过邮件,Facebook和其他社交网站提供通信客户的帐户。因为它们是不同的API,社交和邮件帐户具有不同的接口来实现通信。

Which pattern can be implemented if there is a situation like that in e-commerce system:

There exists a customer and the message (notification) which is about the product's changes like price etc. It is related observer pattern in that notify part. But I have a doubt which design pattern should i use Facade or Adapter while providing communication customers' accounts via mail, or facebook and other social websites. Because they are different APIs and the social and mail accounts have different interfaces to realize communication.

推荐答案

您可以创建一个良好的接口,这是许多其他API的共同点。只有在已经知道其他API及其功能的交集时。通常,好的解决方案不是一个臃肿的想要智能和通用的接口,而是一个只包含软​​件所需的几个简单愚蠢的功能的接口。我建议:1。作为第一个解决方案,创建一个简单愚蠢的界面,反映您的产品的要求。 2.实现许多API的接口。



接口我包含一些函数,如sendNotificationMessage()或like()或其他。接口my包含一些optinal函数,如果不能实现,则不必由所有API实现,也可能是一个可以查询实际实现功能的特殊函数(例如,可以使用类似的东西)。这样一来,如果你需要做一个新的API就是看看应用程序界面的界面,并为给定的API创建一个实现。



在我看来,不要尝试用模式解决所有问题。这个问题太小,无法围绕它构建复杂的系统。历史将决定你是否需要在未来创建系统或经理或处理程序或任何类型的怪物......
You can create a good interface that is a common denominator of many other APIs only if already know the other APIs and the intersection of their functionalities. Often the good solution is not a bloated wanna-be-smart and generalized interface but one that contains only a few simple-stupid functions that are needed by your software. What I recommend: 1. as a first solution create a simple-stupid interface that reflects the requirements of YOUR product. 2. implement the interface for many APIs.

The interface my contain a few functions like sendNotificationMessage() or like() or whatever. The interface my contain some optinal functions that don't have to be implemented by all APIs if implementation is not possible and maybe a special function that can query the capabilities of the actual implementation (for example wheter like-ing is available). This way if a new API comes all you have to do is taking a look at the interface of the interface of your app and create an implementation for the give API.

In my opinion don't try to solve everything with patterns. This problem is too small to build a complex "system" around it. History will decide whether you need to create that "system" or "manager" or "handler" or whatever kind of monster in the future...


请参阅我对该问题的评论。我坚信项目不应该由设计模式驱动,但您的项目应该推动设计模式的选择。很抱歉,如果这个建议不够具体,但它的具体情况并不比您对产品目标的说明要好。







请参阅解决方案1:这是一个好主意:不要尝试用模式解决所有问题。为什么?因为否则你可以把自己放在 Procrustean床 http://en.wikipedia.org/ wiki / Procrustes#Contemporary_usage [ ^ ]。



-SA
Please see my comment to the question. I strongly believe that the project should not be driven by design patterns, but your project should drive the choice of design patterns. Sorry if this advice is not specific enough, but it is no less specific than your description of the goals of your product you need to develop.



Please see solution 1: this is a good idea: "don't try to solve everything with patterns". Why? Because otherwise you can put yourself in a Procrustean bed: http://en.wikipedia.org/wiki/Procrustes#Contemporary_usage[^].

—SA


这篇关于设计模式 - API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆