“Monolithic” page classes - Is this a code smell?

chelar4ever

New Member
I'm new to PHP and I'm trying to build a site for the first time without using a framework (n.b. I have nothing against frameworks, I just think I should learn to code from scratch before learning a framework on top of it. Sort of like learning Javascript before learning JQuery).I like OOP in concept, so I started there. I'm thinking of having a catch all script determine which page type is needed, then passing the (sanitized) script input into the class that handles it, where the class is a subclass of a generic Page class which includes common methods to handle things like sending HTTP codes and with an "virtual" display method to actually display the page.My problem is that it seems like a code smell to have so much happening within the page class itself. Obviously things like talking to databases, sanitizing input, etc. would all be in separate classes, but the individual page classes seem like they'd be huge to contain everything needed to determine the content of the displayed page.Additionally, I have a bit of a problem convincing myself that there's any need for non-private methods inside either Page or its children. I think this is a side-effect in my thinking due to PHP being a scripting language. Since it's a script, it's non-interactive and input data is determined when the script starts (i.e. POST and GET vars). It seems that with no outside influences on a Page except for other objects where the Page is taking in data, rather than providing it, there is no need for a public method except for the constructor, obviously, and the generate method, which I feel could simply be called from within the constructor.I feel like this is a somewhat defensible position, except I ran into this question which seems to indicate that private methods need not be unit tested. In my example, this would lead to a Page class that would only be unit tested via a single "display" method, which definitely seems wrong to me.So tell me: Is my design ridiculously smelly? How can I refactor this into something sane?
 
Back
Top