创建我的软件的API - 基本code结构 [英] Creating an API for my software - Basic code structure
问题描述
我目前正在写一个web软件,该软件也将通过API将使用客户端桌面。
我面对现在的问题是:我应该实现应用程序添加/更新/删除对象两次的每一个动作?一旦因为它坐落在正常code和曾经与世隔绝的API?
I'm currently writing a web software which is also going to be used by Client desktops via an API. The problem I'm facing right now is: Should I implement every action of adding/updating/deleting objects in the application twice? Once as it sits in the normal code and once isolated for the API?
或者我应该更愿意使用重新present所有对象在我的数据库并使用这些API并正常code两者兼而有之?OOP模型类的系统
Or should I much rather use a system of OOP model classes that represent all objects in my database and use those for both the API and normal code?
或开发的API第一手,从我的正常的Web界面也使用它吗?
Or develop the API first hand and use it from my normal web interface too?
这是我一直想知道。在此先感谢!
This is something I have always wondered about. Thanks in advance!
推荐答案
做事两次几乎总是一个坏主意 - 你可能会更好贯彻API,打开它的最终用户,以及使用它为客户code,以及,与东西一些额外的钩子是接口特定的。
Doing things twice is almost always a bad idea -- you're probably better off implementing the API, opening it up to the end-user, and also using it for the client code as well, with some extra hooks for stuff that is interface-specific.
这篇关于创建我的软件的API - 基本code结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!