Skip to main content
clarification copied into question from comments
Source Link
gnat
  • 20.9k
  • 29
  • 115
  • 295

I have started using OOP in PHP recently. For every model, I create two classes. One class for read operations and another Manager class for all the create / update / delete operations. For example,

<?php
// This is a sample class, just to convey the idea
class Image {
    public static function loadById() {}
    public static function loadByName() {}
    public static function search() {}

    public function __construct () {}
    public function __get () {}
    public function getData() {}
    public function getRating() {}
    public function getSimilar() {}
    public function getRelatedNews() {}
}

class ImageManager extends Image {
    public function __construct() {}
    public function __set() {}
    public function remove() {}
    public function update() {}
    public function save() {}
    private function updateSomethingElse() {}
}
?>

The reason I separated this into two classes was that I thought it was a bit more secure, since it did not expose the C/U/D methods to a normal user. Also, I thought this might be faster / memory efficient since I am loading only the smaller class for 95% of the requests. But now I think these reasons are too insignificant for maintaining two files.

Is this a bad practice? Normally, the Manager classes are loaded only during admin operations. User actions rarely update the database (except maybe during a rating operation, or a cron job for updating view count). Should I combine both the classes into the Image class.?

I have started using OOP in PHP recently. For every model, I create two classes. One class for read operations and another Manager class for all the create / update / delete operations. For example,

<?php
// This is a sample class, just to convey the idea
class Image {
    public static function loadById() {}
    public static function loadByName() {}
    public static function search() {}

    public function __construct () {}
    public function __get () {}
    public function getData() {}
    public function getRating() {}
    public function getSimilar() {}
    public function getRelatedNews() {}
}

class ImageManager extends Image {
    public function __construct() {}
    public function __set() {}
    public function remove() {}
    public function update() {}
    public function save() {}
    private function updateSomethingElse() {}
}
?>

Is this a bad practice? Normally, the Manager classes are loaded only during admin operations. User actions rarely update the database (except maybe during a rating operation, or a cron job for updating view count). Should I combine both the classes into the Image class.

I have started using OOP in PHP recently. For every model, I create two classes. One class for read operations and another Manager class for all the create / update / delete operations. For example,

<?php
// This is a sample class, just to convey the idea
class Image {
    public static function loadById() {}
    public static function loadByName() {}
    public static function search() {}

    public function __construct () {}
    public function __get () {}
    public function getData() {}
    public function getRating() {}
    public function getSimilar() {}
    public function getRelatedNews() {}
}

class ImageManager extends Image {
    public function __construct() {}
    public function __set() {}
    public function remove() {}
    public function update() {}
    public function save() {}
    private function updateSomethingElse() {}
}
?>

The reason I separated this into two classes was that I thought it was a bit more secure, since it did not expose the C/U/D methods to a normal user. Also, I thought this might be faster / memory efficient since I am loading only the smaller class for 95% of the requests. But now I think these reasons are too insignificant for maintaining two files.

Is this a bad practice? Normally, the Manager classes are loaded only during admin operations. User actions rarely update the database (except maybe during a rating operation, or a cron job for updating view count). Should I combine both the classes into the Image class?

Post Migrated Here from stackoverflow.com (revisions)
Source Link
Joyce Babu
  • 269
  • 1
  • 7

OOP - Separate Manager class

I have started using OOP in PHP recently. For every model, I create two classes. One class for read operations and another Manager class for all the create / update / delete operations. For example,

<?php
// This is a sample class, just to convey the idea
class Image {
    public static function loadById() {}
    public static function loadByName() {}
    public static function search() {}

    public function __construct () {}
    public function __get () {}
    public function getData() {}
    public function getRating() {}
    public function getSimilar() {}
    public function getRelatedNews() {}
}

class ImageManager extends Image {
    public function __construct() {}
    public function __set() {}
    public function remove() {}
    public function update() {}
    public function save() {}
    private function updateSomethingElse() {}
}
?>

Is this a bad practice? Normally, the Manager classes are loaded only during admin operations. User actions rarely update the database (except maybe during a rating operation, or a cron job for updating view count). Should I combine both the classes into the Image class.