My understanding of MVC-type architectures over the last few weeks/months has advanced (I'd say) considerably, and I owe most of my thanks to fellow SO enthusiasts; so, thank you!
I'm still challenged by something though, the Model
. So far I've sorted out and created;
- A simple
Request
object, that consolidates request data (GET/POST/etc. params, HTTP headers, etc.) - A simple
Response
object, that collects response data (HTML, JSON, HTTP headers, etc.) - A fancy
Router
that resolves URIs against a regex-powered routing table, validates them based onController
file/class existence/inheritance, and updates theRequest
object with any supplementary parameters. - A simple
Dispatcher
object that sets up the working environment, creates and initializes the necessaryController
, and sends it aRequest
andResponse
object to work with.
Now the Model
.
I understand that in many (some) circumstances the Model
is merely representational of it's associated entity, the table, with CRUD methods (addUser()
, deleteUser()
, etc.) In others there are further levels of abstraction, preventing controllers from accessing finer-grain CRUD functionality, consolidating methods (replaceUser()
- deletes, adds, then returns user data)
I'm wondering what my best course of action is; for a few specific reasons.
I've created a Gateway
class that acts as a proxy to an intended Model
, performing ACL checks (using the Acl
object, a special case "Model
") using the Request
and desired method and arguments as parameters for the check. The Controller
is responsible for determining the outcome of a failed ACL check (display all but that data, redirect, etc.)
I've also introduced an (and I've referred to it as hybrid REST/RPC previously, but I believe that's incorrect as my resource URI architecture is out-the-window) RPC API layer. An API call consists of a method, arguments, and request parameters, is managed by the special ApiController
and is fed like a normal Model
call to the Gateway
.
It seems to me like the best way to facilitate data access, would be a (uh-oh) single enormous model object, disregarding any ORM, that maintains all database interaction methods, proving simplicity for managing the Gateway/ACL/Model relationship. No, that sounds wrong.
Given these architectural choices, what may be my best choice for modeling my, um.. Model
? Have I really thrown caution and best-practice to the wind with the aforementioned design choices?