kapeels
kapeels

Reputation: 1702

OOP design - Decentralizing methods in seperate files

I have two files: config.php and init.php.

config.php has a config class with configurations for various server setups. init.php has the init class with all the methods for business logic.

init extends config

I use the ezsql library for MySQL interfacing. I call it as a variable in init ($init->sql). So far so good.

My init.php has grown to be a huge file with numerous methods. Some pages use it just for calling ezsql. I want to move all the methods related to certain area of the site in their respective files and include those files only when I need them.

How do I implement this in actual code?

Upvotes: 0

Views: 68

Answers (2)

Madara's Ghost
Madara's Ghost

Reputation: 174977

If you class is too large, it probably has too many responsibilities. See the SRP. You should probably restructure your application.

Upvotes: 2

artragis
artragis

Reputation: 3713

Perhaps you can use the autoload tool. There is a spl_autoload_register function that allows you to create rules to autoload classes. http://php.net/manual/en/function.spl-autoload-register.php

Upvotes: 0

Related Questions