Skip to main content

Design Pattern, kiến trúc Wordpress so với Framework Front Controller, CMS vs Custom code, design concept, pattern concept ...

MVC là pattern về mặt ý tưởng là tách biệt M V C. Còn cài đặt như nào thì có Front Controller hoặc nhiều controller.
MVC is a general pattern. The idea is to separate three aspects (Model, View and Control) of an application from each other. Now, this idea can be realized in different ways according to specifics of a situation/application. One way is to have many controllers, each responding to an action or a set of actions. Another way is to have one main controller which receives all actions and then dispatches them to different controllers, this one is called Front Controller Patter. So, Front Controller pattern is an MVC Pattern. For example, Spring Framework uses the Front Controller pattern to realize MVC.

Method is actually a function used in the context of a class/object.

When you create a function outside of a class/object, you can call it a function but when you create a function inside a class, you can call it a method.

https://en.wikipedia.org/wiki/Front_controller

https://stackoverflow.com/questions/320142/design-patterns-vs-frameworks
a design pattern solves many software architecture issues (about creation, behavior, concurrency, ...) with different pre-defined design. (design being an implementation of an architecture topic)

a framework is based on the Hollywood Principle (Inversion of Control) ("Don't call us, we call you"), where you implement some high level requirements as specified, and leave the framework do the rest of the work, calling your implementations.

Design vs Architecture
It's really fairly simple: architecture is about the design decision you make to meet the "non-functional" requirements: requirements like cost, maintainability, performance, reliability, availability, and security. This about a web application: you can build it in a zillion ways, from a big C program that runs as a CGI (really, we used to do that), a Python webapp, to a J2EE application, to a LAMP application. Any of them would have the same functional behavior, they all would post the same pages; the differences come in when you try to change the C program's database or load-balance your big LAMP application.

Bob
Architecture is the art of drawing lines. With the interesting rule that once you have drawn the lines, all of the dependencies that cross that line go in the same direction.

https://en.wikipedia.org/wiki/Behavior-driven_development
BDD, DDD, TDD

https://blog.ircmaxell.com/2015/03/thoughts-on-design-of-apis.html
Think about target user of APIs. VD dùng cho angular2 dev. VD hàm hash password dùng cho developer cần dễ dùng vì developer ko rành như computer science hay chuyên gia bảo mật ...

Symfony CMS
http://cmf.symfony.com

http://decoupledcms.org/

https://www.airpair.com/wordpress/posts/developing-wordpress-plugin-from-scratch


Front Controller
Actually, index.php should not contain any meaningful code at all, since it would be only part of your site, that is located inside DOCUMENT_ROOT of webserver. It's content should actually look something like:

<?php

    require '../application/bootstrap.php';
It should only include a file outside DOCUMENT_ROOT. And that's all.

This way, if something goes horribly wrong (like, php extension fails after server update) and visitors are exposed to raw php code, it will not reveal any sensitive details.

The point of Front Controller is handle all user input, turn it into a consumable form and, based on it, dispatch a command (usually in a form of method call on an object). In languages like Java, where everything must be contained in a class, a front controller would be a class. But in php you do not have this restriction.

Instead the front controller will end up being part of your bootstrap stage of the application:

// --- snip --- 
// the autoloader has been initialized already a bit earlier

$router = new Router;
$router->loadConfig($configuration);

$request = new Request;
$request->setUri($GET['url']); 
// could also be $_SERVER['PATH_INFO'] or other
// depends on how url rewrite is set up

$router->route($request);
// the request instance is populated with data from first matching route

$class = $request->getParameter('resource');
$command = $request->getMethod() . $request->getParameter('action');

if (class_exists($class)) {
    $instance = new $class;
    $instance->{$command}($request);
    // you dispatch to the proper class's method 
}

// --- snip --- 
// then there will be some other code, unrelated to front controller
Also, you should keep in mind that concept of front controller is neither made-for nor demanded-by application that attempt to implement MVC or MVC-inspired architecture.

https://mwop.net/blog/260-Dependency-Injection-An-analogy.html
https://blog.ircmaxell.com/2011/03/follow-up-dependency-injection-analogy.html

https://blog.ircmaxell.com/2012/03/handling-plugins-in-php.html
75% dev use CMS
24% use custom code (FW based or not)
1% use both

=> 1%: They pick the right tool for the job.
My hope is that people realize this and stop reinventing the wheel. If you’re getting paid to develop, and you’re first stop is to code, you’re doing something wrong. Often the best solution is one that requires no code. The trick is finding it.


https://blog.ircmaxell.com/2014/12/a-point-on-mvc-and-architecture.html
Really, the answer to “what architecture should I use / is best?” is always, always “it depends”. Architecture can vary widely, as long as it’s deliberate.
deliberate (có chủ ý).

Software design is not about solving problems. It’s about understanding problems. The prime reason that “it depends” is that every problem has different requirements. And a problem isn’t something you can explain to someone in a chat room in five minutes (or if it is, you should be using a CMS in the first place).

The architectural monoculture that has gripped the web dev world since Ruby on Rails came on the scene is quite harmful.

WordPress is not the most well documented framework from the perspective of
architectural diagrams and processes, so you won't fnd detailed explanations on
how plugins actually work behind the scenes.

https://blog.ircmaxell.com/2014/11/alternatives-to-mvc.html

Really understanding framework. Code khi nào dùng FW. Khi nào build dựa trên library. dùng lib make app more robust and overtime, or from start.
https://blog.ircmaxell.com/2012/07/framework-fixation-anti-pattern.html

oop code so với procedural ko đơn giản là class/object. có class nhưng code vẫn theo kiểu procedural.

https://blog.ircmaxell.com/2012/07/oop-vs-procedural-code.html


MVC is that concept and stateful but implement is stateless. And MVC fit Desktop app not web, in web it expensive.
https://blog.ircmaxell.com/2014/11/a-beginners-guide-to-mvc-for-web.html

https://tournasdimitrios1.wordpress.com/2014/07/29/getting-started-with-aspect-oriented-programming-aop-in-php/


Comments

Popular posts from this blog

Rand mm 10

https://stackoverflow.com/questions/2447791/define-vs-const Oh const vs define, many time I got unexpected interview question. As this one, I do not know much or try to study this. My work flow, and I believe of many programmer is that search topic only when we have task or job to tackle. We ignore many 'basic', 'fundamental' documents, RTFM is boring. So I think it is a trade off between the two way of study language. And I think there are a bridge or balanced way to extract both advantage of two method. There are some huge issue with programmer like me that prevent we master some technique that take only little time if doing properly. For example, some Red Hat certificate program, lesson, course that I have learned during Collage gave our exceptional useful when it cover almost all topic while working with Linux. I remember it called something like RHEL (RedHat Enterprise Linux) Certificate... I think there are many tons of documents, guide n books about Linux bu

Martin Fowler - Software Architecture - Making Architecture matter

  https://martinfowler.com/architecture/ One can appreciate the point of this presentation when one's sense of code smell is trained, functional and utilized. Those controlling the budget as well as developer leads should understand the design stamina hypothesis, so that the appropriate focus and priority is given to internal quality - otherwise pay a high price soon. Andrew Farrell 8 months ago I love that he was able to give an important lesson on the “How?” of software architecture at the very end: delegate decisions to those with the time to focus on them. Very nice and straight-forward talk about the value of software architecture For me, architecture is the distribution of complexity in a system. And also, how subsystems communicate with each other. A battle between craftmanship and the economics and economics always win... https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011 1. Independent of Frameworks 2. Testable 3. Indepe