Advertisement

How to split a component model into multiple classes

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
domcdom
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Jun 17, 2024 2:52 pm

How to split a component model into multiple classes

Post by domcdom » Mon Jun 17, 2024 3:01 pm

I've been working on some components which are getting quite large and complex. Its at the point where some of my component models look like procedural code that just happens to be sitting within a class. I'd like to refactor my component models into multiple classes so that I'm able to use OOP principles such as separation of concerns, composition, low coupling and high cohesion.

If I were to split a model up in this way, where would I place my classes? Would a good location just be in the component's model directory?

Are there any examples in the core of models being split in this way?

Advertisement
User avatar
sakiss
Joomla! Explorer
Joomla! Explorer
Posts: 359
Joined: Wed Aug 20, 2008 4:09 pm

Re: How to split a component model into multiple classes

Post by sakiss » Mon Jun 17, 2024 3:55 pm

If a class is not a model (part of the MVC), then there is no reason to be into the Model folder.
But better be under the src folder, in order to follow your namespace convention.

Beyond that, it is a decision of the developer of how he/she organizes the code.

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 362
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: How to split a component model into multiple classes

Post by MarkRS » Wed Jun 19, 2024 7:34 am

A sensible location is a "Helper" folder, under src of course.

You can see that a lot in the core.
It's a community, the more we all contribute, the better it will be.

Advertisement

Post Reply

Return to “Joomla! 4.x Coding”