I've been coding for years and have found myself in a point of frustration. I am working on a new web based service that also has a UI and it will be developed from ground up. It will use some open source components, but is mainly a new thing in its own right.
But here's my problem. Building such a system means building all of those components:
I want all of them to follow the same 'pattern', in a way that a module in the system consists of a folder or set of files that incorporates all of those components within that module.
But I am having a tough time with getting the architecture so that I would like it. Here is what I have so far:
But I do feel really -dirty- for having built the main system in a procedural way. I did start writing it in OOP at first, but quickly found myself in headaches due to having to get everything fit the same system. It was OOP, but it was tightly coupled, which I disliked for while it was written the OOP way, components were really not that independent or were just a hassle to manage.
Are there any patterns or guides I could follow to get a better result? What I like about the current system is that I can call in anything, pre-view-rendering PHP, or HTML views, CSS styling, additional Javascript functions and AJAX communication per-demand, keeping the footpring wonderfully small, but it feels dirty. I even use a global for main database connection (though it is a global object).
Any ideas? It would not be a problem at all if it were just one language, but trying to make everything work together is a bit of a headache.
Thanks!
PHP Design patterns is an Object-Oriented Programming (OOP) concept that is now also used in Drupal 9 projects. With Drupal's adoption of modern PHP and OOP concepts since version 8, design patterns can be leveraged for cleaner and more robust programming.
http://agiletoolkit.org/ implements exactly what you are looking for. It's source-code is available on http://github.com/atk4/atk4 so you can learn from there.
What I learned many things while creating Agile Toolkit.
Look at desktop systems. - Cocoa, Objective Windows and other object-oriented desktop systems have solved those problems long time ago. Create views, connect actions, define call-backs. This maps into HTML-templated views, JavaScript bindings and AJAX requests.
Runtime Object Tree. In Agile Toolkit, the first phase is initialization. During this phase objects are inserted into each-other. For instance you add Button into Form and add Form into Page. Then there is rendering phase which recursively produces HTML from everything. This makes much more sense that having components echo HTML.
jQuery UI widgets. Using those was a great way to solve many problems. Views in Agile Tolokit can talk with respective jQuery UI Widgets.
Objects you have mentioned are "Models" in Agile Toolkit. If you are looking for stand-alone version, you can rely on some ORM framework. I've made my own to have it tighter integrated with the Views.
Reconsider de-coupling. If you are developing all the system by yourself then coupling gives you lots of benefits. Especially if it's object-oriented architecture and you inherit things. You would need some Java experience or Desktop development experience to get this thing right.
Links:
Without knowing anything else, my thoughts:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With