3
votes
2answers
141 views

Extend the class or create an instance?

I'm reading Pro PHP and jQuery and want to rebuild the example. The author is creating a database connection class: class DB_Connect { protected $db; protected function __construct($dbo = NULL){ ...
-1
votes
0answers
48 views

RFC: implement a demo application for OO layout [closed]

I want to create a little demo application to show off and try out my developing "framework". So it should implement most of the use cases I have, be testable, easy to deploy and change. Usually I ...
4
votes
1answer
103 views

Xerox SOLID example in PHP

There is a good example on Wikipedia regarding the violation of SOLID principles. The ISP was first used and formulated by Robert C. Martin while consulting for Xerox. Xerox had created a new ...
1
vote
2answers
189 views

Object Orientation done right with PHP [closed]

I've started to work with web development using PHP as server side programming language. In that time I didn't know the benefits of object orientation and had a hard time trying to write more ...
1
vote
2answers
120 views

Search and Replace in MVC

What would be a good MVC/OOP/GRASP/SOLID structure for a search/replace functionality. Methods: search/searchNext/replace/replaceAll. I'm interested only in the PHP arhitecture and how a professional ...
3
votes
7answers
401 views

OOP (php) for beginners - some unclarities

I started reading some tutorials about OOP, because I want to learn the basics. I have a question about it. I understand how you can have a object "Car" and give it a color like this ...
4
votes
3answers
317 views

Is it acceptable for child classes to “break” parent class functionality?

One of the devs that works with me is following the Open/Closed Principle to add functionality to a Model by extending from our framework ORM. class BaseModel extends ORM { ... } All our models ...
3
votes
1answer
120 views

The Service class in MVC

From time to time I find there is a need to build a service class. Something I can't really attach inside a model in order to respected GRASP and SOLID. So I created a class called ...
0
votes
2answers
124 views

What is a good technique to prevent unauthenticated users from accessing controller methods?

I have an event(s) controller: class Event extends CI_Controller{ public function index(){ } public function foo(){ } //Shouldn't be able to use this method unless logged in ...
1
vote
1answer
124 views

Is it bad practise to create instances from a SQL-query?

I'm researching ways to create a OO-model/repository-layer using PHP's PDO. My idea was to create model classes that represent a domain object and a repository class for each model that has the ...
3
votes
2answers
212 views

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, ...
5
votes
4answers
273 views

Umbrella term for classes that all serve another class

I'm looking for an umbrella term for classes which are separated from a main class in order to achieve necessary encapsulation and keep main class reasonably sized. E.g. each blog post is an ...
4
votes
2answers
868 views

Which of these OOP examples demonstrate proper OOP concepts?

I'm still trying to wrap my head around OOP. All of the following examples work, of course, but is there one (or possibly another) that best exemplifies OOP concepts? /** * For the following ...
5
votes
3answers
248 views

Which of these OOP examples demonstrate proper OOP concepts?

I'm still trying to wrap my head around OOP. All of the following examples work, of course, but is there one (or possibly another) that best exemplifies OOP concepts? /** * For the following ...
4
votes
2answers
313 views

PHP OOP: Should every object contain all the data?

I'm trying to learn PHP OOP "properly", and I was wondering, should the constructor grab all the information in the database and store it in the object? To use an example I'm trying to create using ...
0
votes
2answers
1k views

Simple real-world PHP OOP example?

I'm trying to learn PHP OOP, but when I've followed tutorials, all the examples seem to involve things like: class Human { $_sex; public function setSex($sex) { $this->_sex = ...
-1
votes
3answers
165 views

Changing behaviour of abstract class without modifying subclasses

I am facing a problem with changing behaviour of a library (thus cannot or don't want to change its internals because of future updates, etc.). In this library there is an abstract class which shares ...
1
vote
1answer
270 views

What is a practical level of abstraction in a web application? [closed]

(Originally asked on StackOverflow - http://stackoverflow.com/questions/14896121/what-is-a-practical-level-of-abstraction-in-a-web-application) I still consider myself a newcomer to OO programming, ...
6
votes
4answers
277 views

Applying DRY to an inheritance hierarchy

I'm working on refactoring a legacy application where I implemented the State pattern successfully as shown in the following diagram: As you see there is a common behavior between the 3 states, so ...
7
votes
3answers
334 views

Is it a basic principle, or highly desirable, to have class methods that return “$this” rather than a value?

I've really just begun to learn OOP. I started about a year ago and have written probably 15,000 lines of it. But I wrote it all with hardly any experience looking at other people's OOP. Most of my ...
1
vote
4answers
379 views

mvc pattern on procedural php

First off, I do not have anything against OO programming (I'd be mad if i believed so). But I was thinking on some sort of procedural MVC pattern with PHP; let me explain better. As we all know, ...
0
votes
3answers
151 views

What will be the better way to access information from another object

I have a page Object, which has Paragraph and Image object Collections And each paragraph has only image_id(s) that are assigned to a paragraph. All other information about image is stored in ...
1
vote
4answers
277 views

How to implement classes that should be loaded once?

I'm building a little framework, currently it is just for fun. I'm wondering how should I implement classes that should be instantiated by the framework and be passed to the controller to use? For ...
2
votes
3answers
416 views

OO PHP static keyword, should I use it?

I'm writing script for fb and I have 3 objects that I'll be using through all classes. I'm wondering if there is any advantage in using the static keyword except I don't have to create an instance ...
1
vote
1answer
144 views

Is there a good design pattern for this messaging class?

Is there a good design pattern for this? I want to create a messaging class. The class will be passed: the type of message (eg. signup, signup confirmation, password reminder etc) the client's id ...
3
votes
2answers
644 views

Using PDO with MVC

I asked this question at stackoverflow and received no response (closed as duplicate with no answer). I'm experimenting with OOP and I have the following basic MVC layout: class Model { // do ...
1
vote
1answer
85 views

Fitting an established site into a CI framework

I manage a rather large, feature full nightmare of a site which has no end of feature creep settings/options/etc. Up to now its been coded in a procedural/functional way and would like to move to an ...
-1
votes
1answer
164 views

What type of pattern would be used in this case [closed]

I want to know how to tackle this type of scenario. We are building a person's background, from scratch, and I want to know, conceptually, how to proceed with a secure object pattern in both design ...
0
votes
3answers
223 views

should I extend or create instance of the class

I have two classes Class A and Class B in Class A, i have three methods that perform the save, delete and select operation based upon the object I pass them. in Class B I perform the logic operations, ...
2
votes
1answer
115 views

Validation and Error Generation when using the Data Mapper Pattern

I am working on saving state of an object to a database using the data mapper pattern, but I am looking for suggestions/guidance on the validation and error message generation step (step 4 below). ...
2
votes
1answer
374 views

Why setter method when getter method enough in PHP OOP

I am practicing OOP with PHP, and I am struck at setter and getter methods. I can directly access the class properties and methods with getter method then what's the use of setter method? See my ...
3
votes
1answer
303 views

Domain Models (PHP)

I have been programming in PHP for several years and have, in the past, adopted methods of my own to handle data within my applications. I have built my own MVC, in the past, and have a reasonable ...
0
votes
2answers
234 views

Breaking up a large PHP object used to abstract the database. Best practices?

Two years ago it was thought a single object with functions such as $database->get_user_from_id($ID) would be a good idea. The functions return objects (not arrays), and the front-end code never ...
6
votes
3answers
726 views

What is the difference (if any) between (null != $object) and ($object != null) when using PHP?

I am used to Java and therefore always think conditions are interpreted from left to right, i.e. there is a vital difference in null != $obj and $obj != null Now this seems not to be the case with ...
3
votes
3answers
374 views

Is there a limit on how many global consts are used before an application is considered bad programming?

Basically, I develop websites, some large with many crud operations, etc... However I've gotten into the habit of storing re-usable data as a constant in my PHP applications I currently have 44 ...
5
votes
4answers
550 views

Can a loosely typed language be considered true object oriented?

Can a loosely typed programming language like PHP be really considered object oriented? I mean, the methods don't have returning types and method parameters has no declared type either. Doesn't ...
-3
votes
2answers
352 views

Why don't inherited methods use child properties? (PHP)

I'm trying to get the code below to work in child classes. But it keeps failing because it is checking the basicDbClass rather than the child class. For those complaining and voting my question down ...
1
vote
2answers
331 views

Is it good/safe OOP practice to have a method whose only purpose is to send/retrieve data from another class?

I have a class that performs basic MySQL operations. This is all in PHP. class dbTables { public $name; protected $fields = array(); // array of dbTableField objects public $result_sets = ...
0
votes
3answers
373 views

How important is it to implement a caching system in an MVC style framework?

I am writing my own PHP framework (...waits for the groans to subside) for the purpose of learning (best practices, design principals etc.) as I'm entirely self-taught and consequently there are gaps ...
1
vote
1answer
407 views

A good PHP book [closed]

I am interested in PHP and OOP and I am looking for a nice PHP book with lots of examples and simple, easily understandable texts. I know the basics, so I am not a complete beginner, but I am not very ...
2
votes
2answers
312 views

PHP - Internal APIs/Libraries - What makes sense?

I've been having a discussion lately with some colleagues about the best way to approach a new project, and thought it'd be interesting to get some external thoughts thrown into the mix. Basically, ...
3
votes
2answers
1k views

What is the correct way to implement Auth/ACL in MVC?

I am looking into making a correctly laid out MVC Auth/ACL system. I think I want the authentication of a user (and the session handling) to be separate from the ACL system. (I don't know why but this ...
7
votes
3answers
159 views

Instantiate proper class based on some input

I'm attempting to understand how "switch as a code smell" applies when the proper code path is determined by some observable piece of data. My Webapp object sets an internal "host" object based on ...
0
votes
1answer
200 views

How to access functions in extended classes efficiently?

In PHP I have classes as below class Animal { //some vars public function printname(){ echo $this->name; } } class AnimalMySql extends Animal { static public function ...
0
votes
3answers
242 views

Passing class names or objects?

I have a switch statement switch ( $id ) { case 'abc': return 'Animal'; case 'xyz': return 'Human'; //many more } I am returning ...
1
vote
2answers
369 views

Sharing object between 2 classes

edit: I am thinking that dependency injection is the best approach. I am struggling to wrap my head around being able to share an object between two classes. I want to be able to create only one ...
20
votes
6answers
7k views

How can I apply OOP concepts to building a simple, but real-world, web app?

I've been trying now for a long time to wrap my head around OOP. I see its advantages. I've read many, many tutorials and watched an equal amount of videos on the subject. I get the animal/cat/dog ...
3
votes
2answers
183 views

Should these concerns be separated into separate objects?

I have objects which implement the interface BroadcastInterface, which represents a message that is to be broadcast to all users of a particular group. It has a setter and getter method for the ...
6
votes
4answers
529 views

Design pattern for handling a response

Most of the time when I'm writing some code that handles the response for a certain function call I get the following code structure: example: This is a function that will handle the authentication ...
5
votes
1answer
310 views

Separation of concerns in an RMR framework

I'm working on a new framework for PHP that utilises an architectural pattern called RMR, instead of the more common (pseudo)-MVC that most PHP frameworks currently implement. So far it feels like a ...

1 2