dongningce9075 2013-01-25 12:34
浏览 18
已采纳

在php中构建自己的“小框架”[关闭]

BACKGROUND / IDEA
I am currently working on a small framework just to improve my php-knowledge. This framework should be very simple (minimizing overhead) and flexible in terms of later expansion.

DIFFERENT MEANINGS
As a result of reading more advanced tutorials, notes of serious php-developers, different class structures (singletons, Singletons, dependency injection, JIT, ...), oop, mvc, routing, caching... and a lot more I find it very difficult to filter "the proper way" (if there is one) as it seems to me that everyone says something different.

Many people praise there opinon as "the best" and say that everything appart from that is evil. In my oppinion there is not a right or false. There are just several ways to achieve one's goal.

WHAT I DID SO FAR

  • index: ini settings, define constants, call bootstrap (not oop)
  • booting: autoloader class, namespaces (include files on demand)
  • static classes: htmlManager, fileHandler, databaseManager, ...
  • singletons: none
  • non-static classes: controller, models, views, routes, ...

I know that this is very basic and I did not that much so far but I want to create a solid platform first.

QUESTIONS
Before I want to go any further in my project I'd love to hear your opinion on the things listed below.

  • How do you organise/structure small or even bigger projects?
  • What are your experiences concerning simplicity, logic, performance, readability, expandability and reusability of code?
  • Is there really a "proper way" of coding or it this just interpretation?
  • Is there anything one should not use because it is already obsolete?

WHAT I DON'T WANT TO HEAR

  • Forget about a framework or php
  • Don't do this, don't do that without naming the reason why

Many thanks in prior for every response I get.

  • 写回答

2条回答 默认 最新

  • duanfang5849 2013-01-25 13:30
    关注

    I am currently working on a small framework just to improve my php-knowledge. This framework should be very simple (minimizing overhead) and flexible in terms of later expansion.

    Go for it.

    As a result of reading more advanced tutorials, notes of serious php-developers, different class structures (singletons, Singletons, dependency injection, JIT, ...), oop, mvc, routing, caching... and a lot more I find it very difficult to filter "the proper way" (if there is one) as it seems to me that everyone says something different.

    That's because some people don't have an understanding why something should be solved in a certain way or why something is terrible practice, but they see something on some framework and they think it's the best thing since sliced bread.

    Although opinions may differ, you cannot argue with clean code and proper OOP if that is what you are after. In proper OOP singletons and statics have no place. Also what most people call MVC is actually some wrong view on the pattern (mostly because again they have seen some framework do it some way). Which is not always bad, but it is not MVC.

    Many people praise there opinon as "the best" and say that everything appart from that is evil. In my oppinion there is not a right or false. There are just several ways to achieve one's goal.

    Not everything that isn't the best is terrible in my opinion. But some stuff is just bad practice. And some pattern are defined in a way to make your applications easier to maintain, debug and test. If you are going to implement some other pattern that's all fine with me, but you will loose the benefits of some other pattern.

    Generally speaking the first rule of thumb I use when doing OOP programming is following the SOLID principles.

    static classes: htmlManager, fileHandler, databaseManager, ...

    These have no place in proper OOP. Amongst others because the will tightly coupling the classes. Which make maintainability, readability and testability a pain.

    singletons: none

    Good, because they are just a fancy global.

    How do you organise/structure small or even bigger projects?

    Separation of concerns in both code as structure. One of the pattern can help you with that: MVC, MVP, [MVVM](Model View ViewModel). For me personally I like the MVC pattern the most because it has some nice benefits against other patterns.

    What are your experiences concerning simplicity, logic, performance, readability, expandability and reusability of code?

    Readability and testablity are the most important. Right after that SOLID (which is also handled by the first point (overlap))

    1. Is there really a "proper way" of coding or it this just interpretation?
    2. Is there anything one should not use because it is already obsolete?
    3. Performance

    Forget about a framework or php Don't do this, don't do that without naming the reason why

    As I stated before: Just go for it. Do it and screw it up! Best way to learn is actually doing it and making terrible mistakes. I think the framework I made 1 year ago (although imho still better than 90% of what is out there) is a proper piece of crap ™.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图