instantiation

How to instantiate a certain number of objects determined at runtime?

So here's my problem... Let's say I have a simple "Person" class just with "FirstName" and "LastName" attributes. I want to have a form where the user says how many "Persons" he wants to create and then he fills the name for each one. E.g. user wants to create 20 persons... he puts 20 on a box clicks the button and starts writing nam...

Java: Instantiate or Inheritance?

I am writing a logging service for one of my applications but I am sure many other applications would use this. In that case, would it make sense to make the application extend a class and have all my logging enabled by default (because some logging like application entry point and exit point are required at any cost) in the original cla...

Recurring configurations of a certain class: better to create subclasses or a factory?

Short summary: When you want to predefine certain instantiations of a class, is it better to create subclasses or a factory? Problem Context I have a view helper class MyWebserviceUrl that has a bunch of properties. It's purpose is to generate an url. I would like to be able to have preconfigured instances of this class, so that I do...

instantiated from here error

hi, my compiler is torturing me with this instantiation error which I completely don't understand. i have template class listItem: template <class T> class tListItem{ public: tListItem(T t){tData=t; next=0;} tListItem *next; T data(){return tData;} private: T tData; }; if i try to initialize an object of ...

Value checking logic inside or outside of a class ?

Take this skeleton class that someone wants to fill in to fetch RSS streams on a series of web sites: public class RSSStream extends Thread { public RSSStream(String rssStreamName,String rssURL,int refreshTime){ // constructor code goes here } } Now, let's consider that refreshTime has to be higher than zero and that rss...

What is this method of element instantiation called?

Whenever I create a UIElement in code behind, I'd do something like this: Button button = new Button(); button.Content = "Click Me!"; But then I saw this syntax somewhere, and wanted to know what it's called. I haven't ever seen it used in any of my .NET books: Button button = new Button { Content="Click Me!" }; This is obviously ...

Instantiating class by generic parameter - which method is better.

I have many html forms referring to many persistence classes. All the html forms are generated by one single class HTMLForm by passing in the respective HTMLFields instances: public class HTMLForm<T>{ HTMLForm(HTMLFields[] f, Class<T> classt){ this.stupidSunWontAllowTnewInstance = classt; // ... whatever GWT jazz .... } public...

Specialization of template after instantiation?

Hi, My full code is too long, but here is a snippet that will reflect the essence of my problem: class BPCFGParser { public: ... ... class Edge { ... ... }; class ActiveEquivClass { ... ... }; class PassiveEquivClass { ... ... }; struct EqActiveEquivClass { ... ... }; struc...

Learning JavaScript variable scope and object instantiation.

var foo = (function() { var proxy = {}, warning = false; proxy.warn = function(msg) { if (!warning) { warning = true; alert(msg); } return this; //For the purpose of method chaining we return proxy object. } function func() { alert(warning); //This is a pri...

PHP class instantiation. To use or not to use the parenthesis?

Hey. I've always assumed that - in the absence of constructor parameters - the parenthesis (curly brackets) follow the class name when creating a class instance, were optional, and that you could include or exclude them at your own personal whim. That these two statements were equal: $foo = new bar; $foo = new bar(); Am I right? Or ...

PHP: variable name as class instance

Hey guys, Im having a problem with using a variable as the class name when calling a static function within the class. My code is as follows: class test { static function getInstance() { return new test(); } } $className = "test"; $test = $className::getInstance(); Ive got to define the class name to a variable a...

How to instantiate an object within a linq query

This is kinda theoretical question, I was looking at someone else' code (below) and my simple solution was to instantiate the collection outside linq, but I can guess there will be cases where I'd want to instantiate the objects inside the query, and perhaps only on a selection of elements. Here's a simplified example of how this was be...

Java: Instantiating a generic class with no default constructor

Hi, I am trying to do this: public class BaseTable<T extends TableEntry> { protected int mRows; protected int mCols; protected ArrayList<T> mEntries; public BaseTable(int rows, int cols) { mRows = rows; mCols = cols; mEntries = new ArrayList<T>(); for (int i = 0; i < rows; i++) ...

Why do some classes restrict direct instantiation?

I have encountered various classes that don't allow creation of their instance directly. Rather we have to create their instance from some other class's static method or it own static method. For example: B b = A.getB(); or B b = B.getInstance(); What reason is behind that? Why don't they allow creating instance directly, as in: ...

create a FlashBuilder4 mxml class instance using ActionScript?

I have a number of GUI dialogs defined using MXML. Assuming these mxml objects have been compiled into my application, is there any way to instantiate these objects using ActionScript, sort of like this? myFoo: Mxml2ActionScriptClass("FOO.mxml") = new AutomagicalMXMLFactory( "FOO.mxml"); myFoo.addEventListener(etc etc) th...

How do I force a particular instance of a C++ template to instantiate?

See title. I have a template. I want to force a particular instance of a template to instantiate. How do I do this? More specifically, can you force an abstract template class to instantiate? ...

JFrame not working after first instantiation?

As part of a larger application, I am writing a settings class, which collects and stores user-defined settings. This class is a singleton, and is instantiated during application startup. In order to accept user input, two different GUI frames are insantiated from within ConfigSettings.java, from a public static method, selectSettings(...

C# Delegate Instantiation vs. Just Passing the Method Reference

I have a simple question: what's the advantage of instantiating a C# delegate as opposed to just passing the function reference? What I mean is: Why do: Thread t = new Thread(new ThreadStart(SomeObject.SomeMethod)); When you can do: Thread t = new Thread(SomeObject.SomeMethod); Both will compile and work in my experience...am I m...

Is it better to assign variables in a class itself or in the class' constructor?

This is a sort of design question, and I'm sure there are people who do it both ways. But in your opinion, is it better to assign a variable in the class or in the constructor? For example (regardless of syntax or language, this is just to explain): public class Example { private final int TIME_STAMP = Now(); private int num = 2; ...

Composing a Controller class with Dependency Injection in PHP

How to solve the problem of composing a Controller class in PHP, which should be: easily testable by employing Dependency Injection, provide shared objects for end programmer provide a way to load new user libraries Look down, for controller instantiation with a Dependency injection framework The problem is, that derived Controll...