oop

performance of loading php classes and the use of 'extends'

Hi, I have an includes.php page that I load at the start of every page of my website. As I develop the website, the number of classes that I am using is growing. So I end up with something like this: $db = new DB($config); $login = new Login($db, $config); $form = new Form($db, $config); And the list goes on and on. I have two questi...

Get class name from extended class

Is it possible to get the name of the top level class from an extended class, without setting it from the top level class. See example below, I would like to get 'Foo' from Base. I know I could set a variable from Foo, but hoping to skip the extra step. Thanks. class Base { function __construct() { echo '<p>get_class: '.get_class(...

Is it okay to pass a class object to another class? PHP

I am coding my first object factory, and I am wondering if there any any drawbacks to passing one object into another when creating the second object, and then saving the first object within the second for use later? Example: class main { public $connection = array(); // various other useful functions that should be loaded on ...

setters/getters in one method

Just an idea: example (in PHP): to set name: $object->name('name'); to get name: $object->name(); If no argument: the method is used as getter, else as setter. For simple getters/setter. Stupid, whatever, maybe? edit: to follow up on the answers: I don't really like get and set because I prefer to have the interface as explicit as pos...

Confused about Single Responsibility Principle in the following example

In the following video, the author takes an existing class and assigns the Single Responsibility Principle to it. He takes a Print Class that has the job of Accessing Data, Formatting, and Printing the report. He breaks up each method to its own class, so he creates a DataAccess class to handle data access, he creates a ReportFormatter...

Basic php class problem

Bear with me cos I'm new to oop! Is it possible to assign the result of a function to an attribute? This probably doesn't make sense so here's what I think the code might look like! Class b extends a { public $conn= $this->connect(); public function operation() { ...} } connect() is a function from class a that connects ...

Which design option is more suitable for auto-correction on construction?

Trying to decipher an appropriate OO design to implement. The basic scenario is that you have a PstnNumber which is essentially a 10 digit phone number that always starts with 0 (e.g. 0195550000). A rule has been introduced to allow auto-correcting of a number if the leading 0 is missing (e.g. 195550000). START EDIT I realised the ori...

C++ main() in a large OOP project

This may be a short & simple question, but I've never found a satisfying answer to it: What code does the main() function usually consist of in a large C++ project? Would it be an incorrect assumption to think that it is usually just initializing a (wrapping) class object and calling a function inside of it to set things off? Why is ma...

Multiple language components/classes [OOP/Patterns/IoC/DI]

I have several components for which there exists different versions, depending on the language used by the system (configurable, and can be changed at runtime). For example, I have an interface ("component") for Tokenizer, and two concrete implementations for english and chinese, like so: public interface Tokenizer { List<String> to...

I can't understand the usage of the normal class libraries of the Java

I'm a beginner at Java Programming. I have the experience that I used DX library for before in C++. The DX library worked with simple functions, but the library of the JAVA does not work with functions. How can I understand Java Class libraries? ...

modelling and responsibility

Let's say that you want to create a model of a bank account in your application. You could create a class BankAccount that does what a typical bank account does. But if you're asked what the responsability of the class is, what's the answer? 'Behaving like a bank account?' That's not very concrete. I'm a bit confused on the relationship ...

Singleton vs Static Preference and Defect

Hi, When we want deploy Web Application should we use singleton Object or use Static instead of? what is the bottleneck for use each of them? I should know about Memory Problem , Concurrency problem and ... . P.S: what happen for the class that was just readable (should use static or Singleton) P.S 2: what happen for the class that wa...

data access: exception to 'Tell, don't ask'?

Are data access objects an exception to the rule 'Tell, don't ask'? Eg get last 10 posts from a table data gateway? ...

Why Object.class == Class in Ruby?

I think Object is everyone's ancestor, including Class. So I think it should be Class.class == Object. I feel a bit of confused and twisted ...

Best practice for fetching a collection of items from an object?

I'm dealing specifically with C++, but this is really language-agnostic. Just to give some context into the problem... I have a tree/graph based structure where each node holds a collection of multiple items. I have a class which encapsulates some generic collection (list, map, vector, LinkedList, whatever). I want to be able to fetc...

PHP\MySql Multiuser System Backend Structure

Hey guys I'm writing a multiple user log in system using PHP and MySql, the way i have done it in the past is to have a central "processing" file that will handle all of the code on the backend, like logging in, messaging other users etc..., I've used forms with hidden fields to define which action to perform in the processing file. he...

Accessing singleton methods in PHP

Hi, I'm just starting my journey into OOP - and I'm currently trying to roll my own MVC - purely for learning purposes. I'm working through a tutorial in the Apress PHP-Objects Patterns Practice book. I've created a registry singleton object using the private __construct/__clone technique: class Registry { private static $instance; ...

How do I create a new row without the table class in the Zend Framework?

I understand that you can have class Users extends Zend_Db_Table_Abstract and class User extends Zend_Db_Table_Row_Abstract, setting the $_rowClass property of Users to User. To create and save a new row, I only know how to do the following: $users = new Users() $user = $users->createRow(); $user->name = 'name'; $user->save(); Can yo...

Calling PHP Parent Constructors With Old/New Syntax.

Given the class Foo with an old-style constructor class Foo { public function Foo() { //does constructing stuff } } Is there any functional difference between calling the parent constructor with a new style constructor or the old style constructor? class Bar extends Foo { public function Bar() { //does it matter? //parent:...

Aggregates and Repository. How to determine aggregates?

I have recently been looking at the Repository Pattern as a way of brushing all the details of persistence under the carpet where the client code is concerned. While reading around it appears that a Repository is/can be [usually?] responsible for aggregates rather than just straight-forward classes. This make sense to me as you could h...