oop

Isn't it easier to work with foo when it is represented by the class ArrayList rather than the interface List?

I see this syntax a lot and don't understand the reasoning behind it. I thought you generally want to work with classes rather than interfaces to make it easier to carry out the full panoply of operations you might want to perform. Why do this: List<Foo> foo = new ArrayList<Foo>(something.getFoo()); instead of this: ArrayList<Foo> f...

set_error_handler in codeingiter?

Hey, i've created a few helpers to catch any php errors and then send a curl post which will create a ticket with my bug tracking software. But i can't get it to work with code igniter. Here is my code. <? function phpErrorHandler($errno, $errstr, $errfile, $errline, $errcontext){ //If is a notice do nothing. if($errno == E...

Is there a way to know the name of class from which a method of an object is being called in C++ ??

Suppose in a method MA() of class A, a method MB() of class B is being called after creation of an object. Is there a way to know in MB() the name of the class and the method from which it is being called in C++ ?? ...

What is the difference between C & C# on the basis of OOP concepts?

What is the difference between C & C# on the basis of OOP concepts? ...

When is an "interface" useful?

OOP interfaces. ...

Using a class in PHP4 and i don't know how to set a method

in PHP 5 it would be class Example { private $foo = "old data"; public function __construct(){} public function setVar($data){ $this->foo = $data; } public function output(){ return $this->foo; } } $var = new Example(); $var->setVar("new data"); echo $var->output(); I never learned OO in PHP 4 and am having tr...

How can I get better at OOP?

This might come as a strange question to many of you, and I don't actually know if it is correct to say OOP in this context, because OOP (object-oriented programming) is usually associated with programming languages like C++ and Java, and not lightweight programming languages, or scripting languages. My question, however, is in the categ...

Grouping Related Constants Shared Between Classes

In Effective Java, Item 17, Josh Bloch argues that putting static members into an interface (and implementing that interface) is a bad practice known as the Constant Interface Antipattern: The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implement...

Should I use multiple classes for game?

I'm considering making a text-based RPG-type program in PHP as both a holiday project and a chance to learn more about PHP and OOP. (Maybe not the best choice in language, I know, but I didn't want to have to learn another language from scratch at the same time as OOP.) Anyway, I'm just beginning the design process and thinking about 'm...

Are exceptions in php really that useful?

Hello, 3 days ago I started rewriting one of my scripts in OOP using classes as a practice after reading a lot about the advantages of using OOP. Now I'm confused weather I should use exceptions or not. They seem to make my work harder and longer. My application check if the data was sent through an Ajax request or not then uses that i...

Generic Collections - Ensuring Collections Contain Only One Type of Object?

Hey all, Let me start with the definitions of the objects with which I am working and then I'll do my best to explain what I'm after: class CacheItem<T> where T : EntityBase class CacheCollection : List<CacheItem<EntityBase>> OK, so my generic collection, CacheCollection should be a list of CacheItems which I can manipulate accordin...

Instantiating a generic type?

I'm currently working on a generic collection class and I'd like to create a method which returns an object from the collection. If the specific object does not exist in the collection then the object should be created, added to the collection, and then returned. I'm accounting a few problems though. The generic collection if of a typ...

Usage of Interfaces

Just a clarification from an earlier question about OO PHP. I've checked on the php.net website but still not completely sure. Should be a quick answer, I expect. When 'defining' methods in an interface, must the class that implements it use all the listed methods from the interface? Example: interface foo { public function blah()...

Java: How to extend a base class when other classes already extend the base?

I want to extend a base class in apache commons email, the base class is Email. I simply want to add some throttling to the .send() method 3 other classes extend Email: HtmlEmail, SimpleEmail, and MultiPartEmail There is no factory method for creating these 3 derived classes. Is there a best way that I can extend this one method from ...

Should classes contain references to the objects that populate them?

Say I have the following classes: public class BackendObject {} public class ObjectA {} public class ObjectB { List<ObjectA> Children; } public class ObjectC { List<ObjectB> Children; } and several more levels of objects with children. In my domain, this structure could be quite large, and generating it all (by querying the...

general inheritance (not just) in PHP

Let's have this class class A { protected static function ident() { return "I am A"; } public static function say() { return "I say '".self::ident()."'!"; } } Then I need to extend class A and override the ident() like this class B extends A { protected static function ident() { return "I am B"; } } Now when B::say(); is call...

Abstraction or Inheritance use case?

Hi I'm modeling a UDP communication server in VisualBasic.NET. In my system I have 3 types of messages: basic, advanced and full messages. Basic message is composed of: ID, Version and Serial Number. Advanced message is composed of: basic message + NSeq, IDMsg, Size and CRC. Full message is composed of: advanced message + Timestamp. E...

PHP Inheritance Question

If I have the following class: class foo { function __construct() { // Some code } } And then use inheritance to create: class bar extends foo { // Some code } When I instantiate class 'bar', will it automatically execute the __construct method from 'foo' or do I need to do something else to get that method to e...

Another Inheritance Question

From a quick Google search and a the wikipedia article on Multiple Inheritance, which quotes: Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from ...

In Ruby, must instance variables (of a class) be first defined in "initialize" before it will work?

class Shape def initialize() @blah = "" end end OR...will this work? class Shape @blah = "" def initialize() end end Also, by default, are the instance variables public or private? How do you set them as public or private? ...