oop

Instantiating a Type Parameter Without Passing an Object

My question is very similar to this question. I want to be able to instantiate an object of the type parameter type, but also without needing to pass in a "factory". I really need to be contained all in the one class. public class myClass<E> { E someObject; public myClass(){ someObject = new E(); } } Previous soluti...

Yield from C# to C++, dealing with containers

Hi there. Actually, I have a design question here. Its very simple but the point is: I have one C++ class that has a STL vector declared as a private member. But the clients of that class need to iterate over this vector. In C# we have a very handy statement, the Yield, that in cases like that, you write a function returning an IEnu...

How to access the value of an object from inside a method of the same object in Javascript?

Hi, I'm trying to add a toBool() "method" inside the Object object using prototype... something like this: Object.prototype.toBool = function () { switch(this.toLowerCase()) { case "true": case "yes": case "1": return true; case "false": case "no": case "0": case null: return false; default: return Boolean(string); } } var int...

Php abstract class site configuration

Hi, i have a config class which is an abstract class. I would like to set it up so it automatically detects which server the site is on and then assigns appropriate constants. I get an error on line ten $this->hostName = $_SERVER['SERVER_NAME']; expecting `T_FUNCTION. What is the correct way to do this and is there a better way to do thi...

Abstracting from Stateful object navigation (1-1) - the challenge

Hi, The point of this exercise is to make navigation between objects stateful. For example, having Person and Address with 1-1 association it should: If an address is assigned to a persons, then the person should be assigned to the address (and vice versa). If address is assigned to person1 and then to person2, then the person1 wil...

web services/object-oriented question

Hi, I just recently started with object oriented programming, using java. Before I was programming in old visual basic which wasn't object oriented and in old php which wasn't object oriented .. Now my question : Where can I learn about webservices and object oriented programming through concrete examples? (real life examples not hello...

PHP: get all method names from an object with name "bla_"

I have an object and want a method that returns how much method this Object have that start with "bla_". I found get_class_methods() wich returns all method names, but I only want names which starts with "bla_" ...

Programming Languages - Who Inspired Whom?

Working on PHP frameworks lately, i notice that many of them are inspired by java or ruby frameworks. For instance, the Doctrine ORM is based on RoR's Activerecord (with maybe some elements of Java's Hibernate). The language Groovy is inspired from Java, Ruby and Python. This made me wonder about the history of the many programming langu...

How can I programmatically obtain the max_length of a Django model field?

Say I have a Django class something like this: class Person(models.Model): name = models.CharField(max_length=50) # ... How can I programatically obtain the max_length value for the name field? ...

Using Singletons in PHP

I want to use a DB Singleton i created, in several Methods of a Class. Is it more appropriate to Instantiate the Singleton individually in each Method, or to Instantiate it through the __constructor() and access it from a variable in each method? Thanks. ...

OOP - How to choose a possible object candidate?

I 'm concern about what techniques should I use to choose the right object in OOP Is there any must-read book about OOP in terms of how to choose objects? Best, ...

PHP set current directory to class constant

I have a config file at the root directory of my project which contains a class of constants that are environment specific. The problem I'm having is how to set the current directory as the ROOT var. Something to the effect of: Class Config { const ROOT = dirname(__FILE__); } This isn't possible as it is a constant expression. I've ...

Finding Perimeter and area of a Rectangle object? (C#)

Hi, I know that the formula for finding the area of a rectangle is just length * width, and the peremiter formula is 2(length) + 2(width). My question is, whats the most efficient way to find the area and perimeter of a rectangle object made up of other objects? My Code Snippet: class Rectangle { public Line left { get; set; } publi...

Does static make it slow

Not sure how it works but I have a question:- Does static make the application slow as same variable or method is shared throughout the application, and while one request is using the method or variable other one has to wait for it to be released. ...

Calling subclass's function from superclass based on string in PHP

How would I do something like this: <?php class Controller { var $ActionName; var $PageParameters; function InvokeAction() { $actionFunctionName = ucfirst($this->ActionName); // Call a function named $actionFunctionName // where $actionFunctionName is in a subclass } } ...

Use more specific datatype in overloaded method in java

I have some arraylist with different objects of the same interface type, e.g: Interface interface {} class A implements interface {} class B implements interface {} I also have an overloaded method that implements all those inherited objects of the interface: public void doSomething(A obj) {} public void doSomething(B obj) {} Th...

A function to determine whether one type extends or inherits another in PHP?

Is there a way in PHP to know if one class inherits another? class Controller { } class HomeController extends Controller { } class Dummy { } // What I would like to do $result = class_extends('HomeController', 'Controller'); /// true $result = class_extends('Dummy', 'Controller'); /// false ...

use strategy pattern for billing models that use different data for the calculation?

we have an invoice model that bills clients in a few different ways. for brevity sake, i'm going to focus on two: cost per impression and cost per phone inquiry. my thought was to implement these (and the rest) as strategies and then dynamically mix them in to the invoice class. this seems appropriate because there are different source...

C# using desicion logic to meet these requirements?

I've made a program for my OOP class that does the following: Defines a class to represent complex numbers Uses a constructor to initialize a Complex Number object passes and returns complex number objects from a function tests the complex number class in a driver, and optionally adds and subtracts complex numbers. My Program works a...

Is there a such thing as a routing pattern for websites?

I didn't find any info on searches when I looked this up. I've been doing a lot of research on design patterns but I haven't seen anything as far as routing goes. What I mean is this: back in my php days I would write code on one page and then pass it to the next. That created (though I wasn't aware of it at the time) tightly coupled cod...