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

AWS Elasticache Memcached connection

https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/accessing-elasticache.html#access-from-outside-aws http://hourlyapps.blogspot.com/2010/06/examples-of-memcached-commands.html Access memcached https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/GettingStarted.AuthorizeAccess.html Zip include hidden file https://stackoverflow.com/questions/12493206/zip-including-hidden-files phpmemcachedadmin ~ phpMyAdmin or phpPgAdmin ... telnet mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com 11211 stats items stats cachedump 27 100 https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/VPCs.EC.html https://lzone.de/cheat-sheet/memcached VPC ID Security Group ID (sg-...) Cluster: The identifier for the cluster memcached1 Creation Time: The time (UTC) when the cluster was created January 9, 2019 at 11:47:16 AM UTC+7 Configuration Endpoint: The configuration endpoint of the cluster memcached1.ahgofe.cfg.usw1.cache.amazonaws.com:11211 St...

Notes Windows 10 Virtualbox config, PHP Storm Japanese, custom PHP, Apache build, Postgresql

 cmd => Ctrl + Shift + Enter mklink "C:\Users\HauNT\Videos\host3" "C:\Windows\System32\drivers\etc\hosts" https://www.quora.com/How-to-create-a-router-in-php https://serverfault.com/questions/225155/virtualbox-how-to-set-up-networking-so-both-host-and-guest-can-access-internet 1 NAT + 1 host only config https://unix.stackexchange.com/questions/115464/how-to-properly-set-up-2-network-interfaces-in-centos-running-in-virtualbox DEVICE=eth0 TYPE=Ethernet #BOOTPROTO=dhcp BOOTPROTO=none #IPADDR=10.9.11.246 #PREFIX=24 #GATEWAY=10.9.11.1 #IPV4_FAILURE_FATAL=yes #HWADDR=08:00:27:CC:AC:AC ONBOOT=yes NAME="System eth0" [root@localhost www]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 # Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] DEVICE=eth1 IPADDR=192.168.56.28 <= no eff => auto like DHCP #GATEWAY=192.168.56.1 #BOOTPROTO=dhcp BOOTPROTO=static <= no eff ONBOOT=yes HWADDR=08:00:27:b4:20:10 [root@localhost www]# ...

Rocket.Chat DB schema

_raix_push_notifications avatars.chunks avatars.files instances meteor_accounts_loginServiceConfiguration meteor_oauth_pendingCredentials meteor_oauth_pendingRequestTokens migrations rocketchat__trash rocketchat_cron_history rocketchat_custom_emoji rocketchat_custom_sounds rocketchat_import rocketchat_integration_history rocketchat_integrations rocketchat_livechat_custom_field rocketchat_livechat_department rocketchat_livechat_department_agents rocketchat_livechat_external_message rocketchat_livechat_inquiry rocketchat_livechat_office_hour rocketchat_livechat_page_visited rocketchat_livechat_trigger rocketchat_message rocketchat_oauth_apps rocketchat_oembed_cache rocketchat_permissions rocketchat_raw_imports rocketchat_reports rocketchat_roles rocketchat_room rocketchat_settings rocketchat_smarsh_history rocketchat_statistics rocketchat_subscription rocketchat_uploads system.indexes users usersSessions https://rocket.chat/docs/developer-guides/sc...