instantiation

PHP: string parameter to __construct not passed correctly.

Hi! I'm trying my hand at TDD with PHP and am writing a webbased app to access articles in a MySQL database; this is the test function: class TestArticleTestCase extends UnitTestCase { ... public function testArticleGenerateInsertSqlString() { $testArticle = new Article("12345", "2009-09-13 20:20:20", "Test heading", "Test text")...

Avoid instantiating a class in java

Recently I've faced a question : How to avoid instantiating a Java class? However, I answered by saying: If you don't want to instantiate a class, use "abstract" modifier. Ex: javax.servlet.HttpServlet, is declared as abstract(though none of its methods are abstract) to avoid instantiation. Declare a no argument private constructor. ...

AS3 - Accessing Library Items from outside the Document class

How do you access Library items from classes other than the document class? For example, if I create a movie clip in Flash and Export it for Actionscript with the name Foo, I can do this in the document class: var f = new Foo(); this.addChild(f); And it appears on the stage, as it should. But I need to be able to create other instanc...

How is an instance initializer different from a constructor?

In other words, why would you need an instance initializer? What difference or advantage do you have in writing a instance initializer over a constructor? ...

How to instantiate (inside a method) different classes that implement the same interface?

Hi all Just wondering if you're able to help me with my problem. This has probably come about by my not knowing the right keywords to search for. This is not homework, just anonymised... I have an interface and a bunch of implementing classes: interface Fruit Banana implements Fruit Apple implements Fruit .... I have a Fruit ...

How do you mix old-style and new-style Python classes?

I've seen a few questions on this topic, but I haven't been able to find a definitive answer. I would like to know the proper way to use old-style classes in a new Python code base. Let's say for example that I have two fixed classes, A and B. If I want to subclass A and B, and convert to new-style classes (A2 and B2), this works. Howe...

Why are constructors returned by ReflectionFactor.newConstructorForSerialization() called "munged"?

In Java, one can create instances of a class without actually calling a declared constructor by retrieving one via sun.reflect.ReflectionFactor.newConstructorForSerialization(). As far as I know, this special constructor is called "munged". Where does this term come from? I could not find it in any dictionary. ...

DataTemplate-driven View injection with MVVM

I have a container view that looks something like this <UserControl x:Class="Views.ContainerView"> <UserControl.Resources> <ResourceDictionary> <DataTemplate DataType="{x:Type viewmodels:AViewModel}"> <views:MyView /> </DataTemplate> <DataTemplate DataType="{x:Type viewmodels:BViewModel}"> <views:MyView /> </DataT...

Activator.CreateInstance() troubles

I have a factory that is supposed to create objects that inherit from class Foo at run-time. I would think that System.Activator.CreateInstance's return type was the same as the type of an object it's creating, but judging from the following error message, its return type is Object. Error 1 Cannot implicitly convert type 'object' to ...

difference between server.createObject and createobject in asp classic

according to http://msdn.microsoft.com/en-us/library/ms524620.aspx you should use server.createObject If you are already familiar with VBScript or JScript, note that you do not use the scripting language's function for creating a new object instance (CreateObject in VBScript or New in JScript). You must use the ASP Server.CreateObj...

How Do I Reference a Dynamically Instantiated Object in AS3? (Added a Moviclip to the Stage)

This is something that has been bugging me since I took up AS3 a year ago. Example. I make a class that extends a Movie Clip and call it "LoaderBar" all it is is some text that says "Loading" and below it another movie clip that is a plain rectangle that I call "lBar" When I call a function to load my image I add the Loader to the st...

How to create inline objects with properties in Python?

In Javascript it would be: var newObject = { 'propertyName' : 'propertyValue' }; How to do it in Python? ...

When does it make more sense to use the factory pattern rather than an overloaded constructor to instantiate an object?

In Karl Seguin's Foundations of Programming there is a small section on using the factory pattern. He closes the passage by stating "you can accomplish the same functionality with constructor overloading", but doesn't indicate when or why? So,when does it make more sense to use the factory pattern rather than an overloaded constructor ...

Is there something like PostConstruct for JAXB-annnotated classes?

I need to perform certain operations on a class after it was unmarshalled (after it is constructed by JAXB, rather then by myself). Is there such a functionality in JAXB? If not, how could I achieve it? ...

Instantiating at global level (C++)

Hi, I get the following error with the code below. expected constructor, destructor, or type conversion before '=' token -- #include <string> #include <map> class Foo { }; std::map<std::string, Foo> map; map["bar"] = Foo(); int main() { return 0; } ...

How to make a type safe wrapper around Variant values

I'm working with a OPC Server control that stores data tags as variant types, described by System.Runtime.InteropServices.VarEnum. These types include the following, VT_BSTR (string), VT_I2 (short) and VT_I4 (long). All these values are stored by the server as objects and then I have to cast to the correct value when I fetch them. I kn...

Self Instantiation in Java

How do I self-instantiate a Java class? I should not use any file other than its class file. Also assume that after the line where I initialized the NAME variable, they don't know the name of the class during compile-time. Example: public class Foo implements Bar { public static final String NAME = "Foo"; private void instanti...

How can you instantiate an object with a string and send a parameter in C#?

The code below produces this output fine: This is page one. This is page two. But how do I change it so that the PageItem objects are instantiated dynamically from the List<string>? using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestInstant { class Program { static voi...

Flex Instantiated Object - wait for creationComplete

I have a simple component I created which I instantiate in my main program like so: newMessage = new MessageDetail(); newMessage.body.text = "Hello World"; I receive the error "Cannot access a property or method of a null object reference" on the second line because newMessage was not fully created prior to hitting the second line of ...

Generics and Class.forName

Hi, I would like to create an instance of a specified class using its name. My code is shown below. I get a compiler warning. Am I doing this the right way? Is it even possible to use the name of a class and get an instance of that type back, as I don't think there is any way of the compiler knowing what the type should be? public sta...