oop

Massive dynamic form in PHP: The best approach?

This question is likely to be somewhat longer than SO's average questions, so I'll try to keep it as short as possible: I'm designing a dynamic form that users need to fill in and submit. This form is massive, with over 500 possible questions. The questions displayed to the user depend on answers given in previous answers (for example; ...

PHP OOP extending class can't access database connection

Perhaps you can help. I have a main class that creates a MySql connection. Then I extend this class. I wasn't able to access the connection unless I did a parent::__construct(); and recently while doing this I got an error message that I was out of connections. So how do program this so it doesn't run out of connections and can access ...

How to sort an array of objects in PHP?

Say I have a group of people, each person having a name, sex, and age property, coded like this: public class Person { private $name, $sex, $age; public function Person ($name, $sex, $age) { $this->name = $name; $this->sex = $sex; $this->age = $age; } public function getName(); public function ...

Confused how to setup my class, do't want to expose a comma seperated list, only a collection

So my database has a column which is a comma seperated list of category ID's, like: "1,234,234,23,343,53" My class will have a List property that will expose these ID's in a collection form. If someone wants to add a CategoryID, they just do: myList.Add(234); BUT, when it is time to save to the database, I will have to convert the c...

Cannot implicitly convert type void to IList<int>

string categoryIDList = Convert.ToString(reader["categoryIDList"]); if (!String.IsNullOrEmpty(categoryIDList)) { c.CategoryIDList = new List<int>().AddRange( categoryIDList .Split(',') .Select(s => Convert.ToInt32(s))); } The class has a proper...

Does it make sense to dispatch events from another object?

I'm still trying to get my head around the best way to structure event flows. Someone made a lot of sense by telling me that contained objects should be decoupled from their parent containers so they're reusable between containers. Instead of calling their parent's function, they dispatch an event. Sensible! I recently myself in the awk...

Should I learn recursion before OOP?

I am reading this C++ book, "Problem Solving with C++" in my free time. I have gotten through 4 chapters, and now I am at a split. I can either go to chapter 5 which is file operations and an introduction to OOP, or I can go to chapter 12 which is recursion. So far I have only gone over compiler basics, all that if, else, and loops synta...

Interfaces - Is This Overkill?

This is a pretty basic OO question but I'm curious if I've been going overboard. Let's assume the following hierarchy, which is an example along the lines of what I would typically create: IVehicle - IFlyable - IPlane - Plane - IHelicopter - Helicopter - IDrivable - ICar - Car -...

simple explanation PHP OOP vs Procedural?

Hi, I would like to learn PHP and want to get an Idea about OOP and Procedural. I read some other blogs and tutorials about OOP vs Procedural but I still can't understand the approach. OOP vs Procedural Which I should learn? Whats the difference in code? what are the effects? How can a PHP framework help in OOP aproach? (I would lik...

PHP class def: Individual accessors/mutators or __set() with switch()?

When defining a PHP class, which is preferred/best practice? Are there any key differences I'm overlooking? It seems like it could be more clean, concise, and convenient to write a __set() magic method and put a switch() construct in it with cases for all the private members to which I want to allow access. It wouldn't be called automag...

Good Java application to learn OOD

Hi, I'm looking for an open source java application (C# application is also ok), to learn & understand good Object Oriented design. Specifically, I'm looking for interactions with relational database, so that I can understand the finer details between converting an OO design to non-OO structure. I had a look at some ORM samples. While...

How to access a protected property of Zend_Db_Adapter

Hi all! I've to change the value of protected $_autoQuoteIdentifiers but I don't know how. class ZendX_Db_Adapter_Firebird extends Zend_Db_Adapter_Abstract { protected $_autoQuoteIdentifiers = true; . . . Okay, I can change it directly in the class, but this couln't be the the best way. My application.ini is: resources.db.adapte...

OO data model - can I ignore Object Relational Mapper constraints?

I am just starting to model the data for a new C# project, which must be persistable. Looks like the most natural OO model will have lots of nested .Net generics. Lists of objects, and these objects will also contain Lists of other generic types, and so on, nested at least three levels deep. Ideally, I'd like to just design the data m...

Setting Properties In Once Class, Accessing From Another

Hi. My question is basically this: If I set dynamic data from one class, can I access that same data from another class? Below is the rough pseudocode of what I am trying to do: Public Class Person { public string ID { get; set; } public string Name { get; set; } } And, I do the below: Public Class SomeClass { private voi...

OOP Best Practices When One Object Needs to Modify Another

(this is a C-like environment) Say I have two instance objects, a car and a bodyShop. The car has a color iVar and corresponding accesors. The bodyShop has a method named "paintCar" that will take in a car object and change its color. As far as implementation, in order to get the bodyShop to actually be able to change a car object's c...

What's the life span of a variable in a program (in Java)?

Can you tell me how long a variable lives in a program (in Java). i.e. variables declared inside methods, variables used in parameters, STATIC variables, variables used to return from a method, etc. Thanks. ...

Static allocation vs. Dynamic allocation vs. Automatic allocation

What are the differences among static, dynamic, and automatic allocation? ...

PHP's magic method __call on subclasses

My situation is best described with a bit of code: class Foo { function bar () { echo "called Foo::bar()"; } } class SubFoo extends Foo { function __call($func) { if ($func == "bar") { echo "intercepted bar()!"; } } } $subFoo = new SubFoo(); // what actually happens: $subFoo->bar();...

Approaches for caching calculated values

In a Delphi application we are working on we have a big structure of related objects. Some of the properties of these objects have values which are calculated at runtime and I am looking for a way to cache the results for the more intensive calculations. An approach which I use is saving the value in a private member the first time it is...

A practical object-oriented design question

I'm making the switch to a more object-oriented approach to ASP.NET web applications in a new system I'm developing. I have a common structure which most people will be familiar with. I have a school structure where there are multiple departments; courses belonging to a single department; and students belonging to multiple courses. In...