简体   繁体   English

有关如何设计框架的资源

[英]Resources on how to design a framework

是否有关于如何设计框架的资源,例如技巧和窍门,最佳实践等。

For .NET there's 对于.NET,有

Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries 框架设计指南:可重用.NET库的约定,惯用语和模式
http://www.amazon.com/Framework-Design-Guidelines-Conventions-Libraries/dp/0321545613 http://www.amazon.com/Framework-Design-Guidelines-Conventions-Libraries/dp/0321545613

You can also study frameworks like Spring . 您还可以研究诸如Spring之类的框架。

Google技术讲座讲座“ 如何设计好的API及其重要性”提供了有关如何设计好的API的许多见解。

In regards to PHP ehre are some Tips from me: 关于PHP ehre是我的一些提示:

Use MVC as your framework type. 使用MVC作为您的框架类型。

MVC (Model-View-Controller) is the best way to create a framework, keeping your Logic and Models separate to your Views etc is the best way to accomplish a fresh clean application. MVC(模型-视图-控制器)是创建框架的最佳方法,将逻辑和模型与视图等分离是完成全新应用程序的最佳方法。

I believe thatStack Overflow uses a MVC pattern, Not sure if its PHP / ASP tho. 我相信Stack Overflow使用MVC模式,不确定其PHP / ASP是否。

Make your code as open as possible. 使您的代码尽可能开放。

Meaning that practically any object is accessible throughout the application. 这意味着实际上整个应用程序都可以访问任何对象。

A way i achive this is by creating a static class that as a global scope to overcome the problem, for example: 我达到此目的的一种方法是,创建一个静态类作为全局范围来解决该问题,例如:

class Registry{....}

Registry::add('Database',New Database);
Registry::add('Input',New Input);
Registry::add('Output',New Output);

then anywhere throughout the application you can easily get objects like so: 然后在整个应用程序中的任何地方,您都可以轻松地获得如下对象:

Regsitry::get('Database')->query('Select .... LIMI 10')->fetchObject();

Do not use template engines 不要使用模板引擎

In my eyes template engines are not the best as PHP is itself a template engine, there's no need to create a lot of code to parse your templates and then have PHP parse it again, its logical. 在我看来,模板引擎并不是最好的引擎,因为PHP本身就是模板引擎,不需要创建大量代码来解析您的模板,然后让PHP再次解析它,这是合乎逻辑的。

Instead create an system where the user will tell the View what template file to output and check the catch for that, if its not in the cache then that object will transfer it to another object called lets say ViewLoader, Witch within the __Construct it includes the php template file, but also has other methods like url() and escape() etc so in tempalte fiels you can then use 而是创建一个系统,用户将告诉View要输出的模板文件并检查其内容,如果该文件不在缓存中,则该对象会将其传输到另一个名为的对象,比如说ViewLoader,在__Construct中的Witch包括php模板文件,但也具有其他方法,例如url()escape()等,因此您可以在临时字段中使用

$this->url('controller','method',$this->params);

Hope this helps you! 希望这对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM