oop - Modular design and intermodule references -
i'm not sure title match question want put on table.
i'm planning create web mvc framework graduation dissertation , in previous conversation advisor trying define achivements, convinced me should choose modular design in project.
i had things developed , stopped while analyze how modular , couldn't because don't know real meaning of "modular".
some things not cleary me, example, referencing module blows modularity of system?
let's have database access module , optionaly can use cache module storing results of complex queries. can see, @ least have naming dependency cache module.
in conception of "modular design", can distribute each component separately , make interact others developed other people. in case showed, if wants use database access module, have take cache well, if not use it, referencing/naming purposes.
and so, wondering if modular design yet.
i came alternative creating each component singly, without don't knowing existance of other components not absolutely required functioning. extend functionalities, create structure based on decorators , adapters.
to clarify things little bit, here example (in php):
before
interface cache { public function isvalid(); public function setvalue(); public function getvalue(); } interface cachemanager { public function get($name); public function put($name, $value); } // concrete implementations... interface dbaccessinterface { public docomplexoperation(); } class dbaccess implements dbaccessinterface { private $cachemanager; public function __construct(..., cachemanager $cachemanager = null) { // ... $this->cachemanager = $cachemanager; } public function docomplexoperation() { if ($this->cachemanager !== null) { // return cache if valid } // complex operation } } after
interface cache { public function isvalid(); public function setvalue(); public function getvalue(); } interface cachemanager { public function get($name); public function put($name, $value); } // concrete implementations... interface dbaccessinterface { public function docomplexoperation(); } class dbaccess implements dbaccessinterface { public function __construct(...) { // ... } public function docomplexquery() { // complex operation } } // , integration module class cacheddbacess implements dbaccessinterface { private $dbaccess; private $cachemanager; public function __construct(dbaccessinterface $dbaccess, cachemanager $cachemanager) { $this->dbaccess = $dbaccess; $this->cachemanager = $cachemanager; } public function docomplexoperation() { $cache = $this->cachemanager->get("foo") if($cache->isvalid()) { return $cache->getvalue(); } // complex operation... } } now question is: best solution? should modules not have requirement work together, can more efficient doing so?
anyone in different way?
i have more further questions involving this, don't know if acceptable question stackoverflow.
p.s.: english not first language, maybe parts can little bit confuse
some resources (not theoretical):
c++ plugin architecture (use noscript on side, have weird login policies)
other threads (design pattern plugins in php)
django middleware concept
Comments
Post a Comment