oop

Check if function has been called yet

New to OOP in PHP One of my functions requires another function to be executed before running. Is there a way I can check this? ...

Why aren't hot-swappable vtables a popular language feature?

In object-oriented programming, it's sometimes nice to be able to modify the behavior of an already-created object. Of course this can be done with relatively verbose techniques such as the strategy pattern. However, sometimes it would be nice to just completely change the type of the object by changing the vtable pointer after instant...

Class implementing interface as method return type in C#

Is it possible in C# to define return type of a method as some class that additionally implement some interface? For example, in GTK# application I would like to have a widget to display documents. I would like to provide several implementations of that widget - one based on Gecko, one on Webkit and one, basic,on regular Gtk.TextView. C...

What's an elegant and easy way to construct XML from a custom object?

I need to construct an XML transaction of the following format: <RateV3Request USERID="MyId"> <Package ID="1ST"> <Service>ALL</Service> <FirstClassMailType>LETTER</FirstClassMailType> <ZipOrigination>06226</ZipOrigination> <ZipDestination>06231</ZipDestination> <Pounds>0</Pounds> <Ounc...

Can you write any algorithm without an if statement?

This site tickled my sense of humour - http://www.antiifcampaign.com/ but can polymorphism work in every case where you would use an if statement? ...

The right way to handle additional user data in Django?

I need to attach a significant number of additional properties to every user in my Django project. Some of these properties are simple CharFields, others are more complex ManyToManyFields. The trouble for me, is that in my digging around of ways to do this, I've found two options: The user profile method explained in the documentation,...

C++ design question

Suppose I have a class Base which has a member variable A* my_hash. I also have class Extended which inherits from class Base. I also have a class B which extends A. class Base{ Base(): my_hash(new A) {} //methods which use my_hash protected: A* my_hash; }; class Extended:public Base{ //methods which use my_hash from A //I can...

Coming from C to C++

HI all. I have started a new job recently where I am supposed to work with C++/ I have been doing programming in C language for past 5 years. I am looking for ways to get me up to an acceptable level in OOP. I have all the basic concepts of C++ and OOP but don't have much experience of actual class designing. What I really am looking for...

Accessing a function in a class from other classes

What I want to do is access the query function in my database class form anther class. Evey time a query is done I track the time it takes and add the the query count, I want to do that for all query's. The layout I have now is: Global ----------------------------- | | database class ...

OO design patterns for multi-threaded synchronisation

Are there any generalisations of object and data and thread interactions given design pattern names? Obviously what goes on a lot is synchronisation on an object, passing messages through a queue and also reference counts in memory management systems. But are there any more OO-oriented names for multithreading design patterns and syste...

How to access to the parent object in c#

Hi, I have a "meter" class. One property of "meter" is another class called "production". I need to access to a property of meter class (power rating) from production class by reference. The powerRating is not known at the instantiation of Meter. How can I do that ? Thanks in advance public class Meter { private int _powerRating ...

Data types compared to OOP objects

Is a data type a piece of code? In other words, is it software? I'm talking about fundamental data types like integer, char, etc. If so, does that indicate that objects in OOP programming are extensions of data types? That is, basically, have programmers taken data types to another level in creating objects? ...

Java class with only static fields and methods - bad or good practice?

I have a Java class that only consists of static member variables and static methods. It is basically serving as a utility class. Is this a bad practice to have a class that only consists of static member variables and static methods? Thanks Steve ...

Zend Cache Howto PHP

How can i do the followin tasks public function addToCache($id,$items) { // in zend cache } public function getFromCache($id) { // in zend cache } The first method should take an id and items which should be cached. The second method should just take an id of an cached object, and should return the content of the cache of that it...

Base Class Awareness of Property Changes in Derived Classes

I was wondering if anyone had a possible solution to the following problem... I have a base class that a series of derived classes will inherit from. The base class cares about whether properties on the derived class have changed. This is to set up an "IsDirty" approach for a data transfer object. The traditional approach would be to...

Ruby abstraction

I'm new to Ruby, coming primarily from C# and ActionScript 3 (among other langauges). I'm curious about abstracting functionality. Specifically, wrapping and abstracting Ruby's FTP and SFTP libs. I was searching around and came across a gem called Backup. It really got my attention because it supports backing stuff up via S3, SCP, SF...

Write-only accessors in Actionscript 3: Bad Practice?

I just can across some code where they've got an implicit setter, but no getter eg: public class Person { //no getter! public function set food(value:Food):void { // do something with food. this.processFood(value); this.dispatchEvent(new Event(FoodEvent.EATEN)); } } This smells bad to me. Hacky. W...

PHP: How to call function of a child class from parent class

Hi, How do i call a function of a child class from parent class? Consider this: class whale { function __construct() { // some code here } function myfunc() { // how do i call the "test" function of fish class here?? } } class fish extends whale { function __construct() { parent::construct(); } function...

How to learn designing applications in Java

Hi I have been programming in Java for the past 2 years and now i want to get into Designing applications. So far i am only into coding ie; i am given design document/class diagram etc and asked to code. Now i want to learn how to design, i mean i want to lean when should a class be interface not a concrete class, coming up with design g...

Constructor: Full fledged or minimal?

When designing classes you usually have to decide between: providing a "full" constructor that takes the initial values for all required fields as arguments: clumsy to use but guarantees fully initialized and valid objects providing just a "default" constructor and accessors for all necessary fields: might be convenient sometimes but d...