solid mvc - thephp.cc fileprobably the widest quoted pattern in ui development is model view...
TRANSCRIPT
![Page 1: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/1.jpg)
SOLID MVCStefan Priebsch | Bulgaria PHP Conference 2015
![Page 2: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/2.jpg)
Stefan PriebschConsultant and coach. Helps teams to successfully develop software.
![Page 3: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/3.jpg)
sharing experience
![Page 4: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/4.jpg)
MVC ?
![Page 5: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/5.jpg)
Controller
ModelView
![Page 6: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/6.jpg)
![Page 7: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/7.jpg)
Probably the widest quoted pattern in UI development is Model View Controller
(MVC) - it's also the most misquoted. I've lost count of the times I've seen
something described as MVC which turned out to be nothing like it.
http://martinfowler.com/eaaDev/uiArchs.html
“
![Page 8: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/8.jpg)
"A Framework is no architecture"Ask your favourite search engine for more information
![Page 9: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/9.jpg)
SOLID ?
![Page 10: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/10.jpg)
[SOLID] stands for five basic principles of object-oriented programming and
design.
[...]
The principles, when applied together, intend to make it more likely that a
programmer will create a system that is easy to maintain and extend over time.
https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
“
![Page 11: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/11.jpg)
![Page 12: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/12.jpg)
SOLID• Single Responsibility Principle• Open/Closed Principle• Liskov Substitution Principle• Interface Segregation Principle• Dependency Inversion Principle
![Page 13: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/13.jpg)
Single ResponsibilityThere should never be more than one reason for a class to change
![Page 14: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/14.jpg)
Open/Closed PrincipleCode should be open for extensions, but closed for modifications
![Page 15: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/15.jpg)
Liskov Substitution PrincipleIn short: inheritance sucks
![Page 16: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/16.jpg)
Interface SegregationClients should not be forced to depend upon interfaces that they do not use
![Page 17: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/17.jpg)
Dependency InversionA. High-level modules should not depend on low-level modules.
Both should depend on abstractions.
![Page 18: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/18.jpg)
Dependency InversionB. Abstractions should not depend on details.
Details should depend on abstractions.
![Page 19: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/19.jpg)
Infrastructure
Domain
![Page 20: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/20.jpg)
Infrastructure
Domain
A
I
![Page 21: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/21.jpg)
<?php
class FooController extends FrameworkController
{
public function indexAction()
{
...
}
public function createAction()
{
...
}
public function deleteAction()
{
...
}
...
}
![Page 22: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/22.jpg)
<?php
class IndexController extends FrameworkController
{
public function indexAction()
{
...
}
}
class CreateController extends FrameworkController
{
public function createAction()
{
...
}
}
...
![Page 23: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/23.jpg)
<?php
class IndexController extends FrameworkController
{
public function run()
{
...
}
}
class CreateController extends FrameworkController
{
public function run()
{
...
}
}
...
![Page 24: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/24.jpg)
<?php
interface Controller
{
public function run();
}
![Page 25: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/25.jpg)
<?php
class IndexController ...
{
public function process(HttpRequest $request)
{
...
}
}
class CreateController ...
{
public function process(HttpRequest $request)
{
...
}
}
...
![Page 26: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/26.jpg)
<?php
interface Controller
{
public function process(HttpRequest $request);
}
![Page 27: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/27.jpg)
<?php
class IndexController ...
{
public function process(HttpGetRequest $request)
{
...
}
}
class CreateController ...
{
public function process(HttpPostRequest $request)
{
...
}
}
...
![Page 28: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/28.jpg)
<?php
interface Controller
{
public function process(HttpRequest $request);
}
![Page 29: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/29.jpg)
<?php
class FrameworkController
{
protected function getRequest() {...}
protected function getFactory() {...}
protected function getServiceContainer() {...}
...
}
![Page 30: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/30.jpg)
![Page 31: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/31.jpg)
<?php
class MyController extends Framework_Controller
{
public function someAction()
{
global $templating;
global $router;
global $mailer;
// ...
}
}
![Page 32: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/32.jpg)
<?php
class YourController extends FrameworkController
{
public function someAction()
{
// ...
... $this->retriveFromDiContainer('something') ...
// ...
}
}
![Page 33: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/33.jpg)
<?php
class YourController extends FrameworkController
{
public function someAction()
{
// ...
... $this->retrieveSomethingFromDiContainer() ...
// ...
}
}
![Page 34: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/34.jpg)
<?php
class YourController extends FrameworkController
{
private $something;
public function __construct(Something $something)
{
$this->something = $something;
}
public function someAction()
{
// ...
... $this->something->doStuff() ...
// ...
}
}
![Page 35: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/35.jpg)
Dependency Disguise is an Antipattern
![Page 36: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/36.jpg)
<?php
class YourCode
{
private $dependency;
public function __construct(
SomePartOfTheFramework $externalDependency
)
{
$this->dependency = $externalDependency;
}
// ...
}
![Page 37: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/37.jpg)
<?php
class YourCode
{
private $dependency;
public function __construct(
SomePartOfTheFrameworkButItIsAnInterface $externalDependency
)
{
$this->dependency = $externalDependency;
}
// ...
}
![Page 38: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/38.jpg)
<?php
class YourCode
{
private $dependency;
public function __construct(
InterfaceDefinedByFramework $externalDependency
)
{
$this->dependency = $externalDependency;
}
// ...
}
![Page 39: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/39.jpg)
<?php
class YourCode
{
private $dependency;
public function __construct(
InterfaceDefinedByYou $internalDependency
)
{
$this->dependency = $internalDependency;
}
// ...
}
![Page 40: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/40.jpg)
<?php
interface YourSomethingLoaderInterface
{
public function loadAllSomethings();
}
![Page 41: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/41.jpg)
<?php
class YourLoader implements YourSomethingLoaderInterface
{
private $thing;
public function __construct(FrameworkLoaderMagicComponentThing $thing)
{
$this->thing = $thing;
}
public function loadAllSomethings()
{
... work with $this->thing ...
... and convert the result back to a SomethingCollection ...
}
}
![Page 42: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/42.jpg)
Infrastructure
Domain
A
I
![Page 43: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/43.jpg)
<?php
class SomethingModel
{
public function __construct(Session $session)
{
...
}
}
![Page 44: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/44.jpg)
<?php
class SomethingModel
{
public function __construct(ApplicationState $applicationState)
{
...
}
}
![Page 45: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/45.jpg)
<?php
class SomeController extends FrameworkController
{
public function indexAction()
{
...
$this->redirect(...);
}
}
![Page 46: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/46.jpg)
<?php
class FooController extends FrameworkController
{
public function indexAction()
{
...
$view->setData(...);
}
}
![Page 47: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/47.jpg)
Summary:MVC usually does not apply to your problem,
but makes it super-simple to write non-SOLID code.
![Page 48: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/48.jpg)
Summary:You are responsible for the quality of your code.
![Page 49: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/49.jpg)
Warning Signs:First, you decide which framework to use
![Page 50: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/50.jpg)
Warning Signs:You put code into the framework
![Page 51: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/51.jpg)
Warning Signs:You consider migrating from one framework to another
![Page 52: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/52.jpg)
Warning Signs:Your methods do not fit on one screen
![Page 53: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/53.jpg)
Warning Signs:You are unsure whether to put something into a controller, or into a model
![Page 54: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/54.jpg)
Warning Signs:You have a hard time naming classes and methods
![Page 55: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/55.jpg)
http://thePHP.cc
@spriebsch
![Page 56: SOLID MVC - thephp.cc fileProbably the widest quoted pattern in UI development is Model View Controller (MVC) - it's also the most misquoted. I've lost count of the times I've seen](https://reader030.vdocuments.net/reader030/viewer/2022041208/5d64e39d88c99317158b8be9/html5/thumbnails/56.jpg)
sharing experience