Hi all
(disclaimer: if i am speaking gibberish in the post then i apologies as I’m a little ill today haha)
So i am highly new to the concept of OOP code and am trying to create a few projects to get my head fully around it.
I know the usual – mammal – dog – barks concept.
In my current website that i am creating for an assignment i thought creating a forum would be a good idea so why not make it OOP?
My first idea was simple,
All forums have subjects (or sections)
All subjects have threads
All threads have posts
So a class would be made for each that extended from forum. This idea cannot work (for me at least) because:
If a forum class were to be put on the forum pages which linked to a forums database with that forums name (so a construct parameter “forum name”) it would do a query to find all subjects and display then. However, if this then made a subject class for each result it would be making that many forums (due to the classes being extended). This problem would then keep going down the tree ending up with each post being a new instance of a forum … umm .. yer.
Cleary that logic is flawed and therefore, so is my idea of how classes should be implemented.
Coming from a JavaScript background (if you can call 2-3 years a background), i am use to making everything a function and keeping code clean by doing so. Eventual however, i still find this gets messy so i would like to get into OOP programming as soon as possible.
After coming to the above conclusion i then removed to extended logic and made them separate classes. If you then think that a forum instance would create several subject instances and so forth this then begins to work but isn’t this just making fancy functions? – if the classes don’t actual link together.
So, i ask you, how would you go about doing this? Would you at all, or would this be a procedural piece of code?
side note: in terms of the database that would behind this, unless being oop changes this, I am competent enough to need no help with, so in any replies don’t worry about going into that side of it.
Thanks for any replies/ideas.