PHP aggregation coupling???
This is a generic model interface:
PHP Code
Interface api{public function Main (); Public function params ($value);}
The generic model class then inherits it:
PHP Code
Class Test implements API {public function main () { echo ' Hello world! ';} Public function params ($value) { var_dump ($value);}}
Front-end controller, parsing the URL after instantiating the model class, invoking the interface, passing model data:
PHP Code
Class Control{private function __construct () { self::router (); $obj = new self:: $Model (); Self::_interface ($obj);} public static _interface (API $obj) { $obj, main (); $obj, params ();}}
This is my simple coupling structure, but this is only relative to the coupling between the controller and the model class, but also the general class, if the special class has to use a special interface and controller, but the problem is not here, the problem is that I want to let the model also through interface interaction (data coupling? ), but think a lot of there is no practical solution, how to do this interface???
For example, I need to invoke a function of a database class, which is normally called directly:
$db = Db::main ();
#db, Query (***********************);
However, this does not conform to the concept of low coupling, I only need to change the query (), the method is finished, there is no way to pull the data??
Or, to a data-coupled example of the line, I slowly study it ....
Thank you!
(Note: I know that some people might say that the above code is perfect or something.) Indeed, I am the front controller of some things are integrated, but this is not the focus of my discussion today, if you bring a visual inconvenience, please forgive me)
------Solution--------------------
To be honest, I really don't understand what you're going to do ...
But the data layer to interact, obviously should be done through the control layer, otherwise what to control the layer to do? Because only the control layer knows what the specific business logic of the relationship between the data, and the model should only be concerned about its own acres of three points, beyond this range should be handed over to the upper processing, so that the coupling is reduced!
Also mentioned in the $db->query problem, obviously can be extracted by the field, conditions, sorting, etc., to convert the query into
$db->select ()->where ()->order ()->limit ()
Here are 2 ways to do it:
1 and then the abstraction
$DB:: Fetch ($where, er, $limit) {
return $db->select (' * ')->where ($where)->order ()->limit ();
}
Call the time
$db = Db::main ();
$db->fetch ($where, er, $limit);
2 or you can encapsulate a lower-level model base class
Basemodel::fetch ($where, er, $limit) {
$db = Db::main ();
return $db->select (' * ')->where ($where)->order ()->limit ();
}
Model Basics
Class Test extends Basemodel implements API {
function dothing () {
Parent::fetch ($where, er, $limit);
}
}
Without understanding what this has to do with data coupling, this is just the encapsulation of the call DB!
------Solution--------------------
2 floor to say the rational, I personally think that the way to reduce the coupling is to show that the layer is only responsible for the display, logical processing to a business logic layer, the data access layer to deal with data, a thing to do!
About the database class problem, I suggest you go to see Uchome database class, I think his class write well, with 2 floor said more similar!
------Solution--------------------
Since it is the base class of the controller. Can the controller not all follow the standard execution data provided by the base class?
------Solution--------------------
I thought you were supposed to get into a misunderstanding by a variety of nouns.
You actually want to pass a message between the various function modules.
In fact, this is a very easy implementation of a mechanism, the operating system is widely used in the event-driven or message-driven
A module broadcasts its own requirements, and the module that implements the requirement returns the required data for this requirement