constructor

Structuremap resolve tpye with parameters

Hi, I have a problem.... Lest say I have a class like this one: public class A: InterfaceA { private FileInfo _fileInfo = null; public A(FileInfo fileInfo) { this._fileInfo = fileInfo; } ... } and another one: public class B: InterfaceB { private A _classA = null; public B(A classA) { ...

C# Constructor parameter passing

I currently restruct my program to be more object-orientated and I'm having trouble with the constructors of my objects. All objects are stored in a database which has to be human-readable, so I figured it would be nice for the programmer to pass the constructor of an object the table or datarow directly and the object would get the val...

C#: How to create a generic superclass to be extended by non-generic subclasses

I have a bunch of Repository classes which all look a bit like the following. Note that I have omitted certain methods; I just want you to get a flavour. public class SuggestionRepository : ISuggestionRepository { private IUnitOfWork _unitOfWork; public SuggestionRepository(IUnitOfWork unitOfWork) { _unitOfWork = un...

Throwing ArgumentNullException in constructor?

For a constructor with a single parameter, is it OK to throw an ArgumentNullException inside the constructor if the parameter is null/empty? OR, should it be thrown in the method that actually uses the argument? Thanks. ...

ExtJs - FormPanel not rendering properly

Hello guys! I have constuctor (window + formPanel) AddOrgWindowUI = Ext.extend(Ext.Window, { title: 'Create something', width: 400, height: 200, layout: 'fit', initComponent: function() { this.items = [ { xtype: 'form', id: 'add-form', padding: 5, initialConfig: Ext.apply(this...

C# static garbage collector?

I have a simple class which has a static constructor and a instance constructor. Now when i initialized the class , both static and instance constructor are called. Only static is referred once in a application domain . Can i again call the same class initialization and static constructor initialize again? I have tried but it didn't happ...

Reference Member Required to be Const?

In this simple example, why do I need to make 'member' const in order to get this to compile? struct ClassA { ClassA(int integer) {} }; struct ClassB { ClassB(int integer): member(integer) { } const ClassA& member; }; int main() { ClassB* b = new ClassB(12); return 0; } Otherwise, I get this err...

Better pattern for construction of this object?

I am constructing enum values that have a data structure like the following: enum MetaType { HUMAN( new MetaTypeAttribute(AttributeType.BODY, 1, 6), new MetaTypeAttribute(AttributeType.AGILITY, 1, 6), new MetaTypeAttribute(AttributeType.REACTION, 1, 6) ), ORK( new MetaTypeAttribute(AttributeType.BODY, 4, 9), new MetaTypeAtt...

Incorrect data in Constructor

I have a class class Rational { private int _n; private int _m; public Rational(int n, int m) { _n = n; _m = m; } } But m should be > 0. What should I do to notify user that he enter incorrect data to constructor? ...

Can I say a Constructor is a Method?

I wonder if can I say that a constructor is a special case of a method? ...

conversion from 'std::string' to non-scalar type requested

I have trouble implementing my class. It should be able to initialize from std::string. So I wrote a copy (?) constructor: CVariable (std::string&, const int p_flags = 0); I'm trying to make an object of CVariable: MCXJS::CVariable s_var = (string)"good job"; I'm getting the following error: F:\Projekty\MCXJS\src\main.cpp|8|error:...

AspectJ, general pointcuts without constructors

Hi guys, I've made a profiling method: @Around("tld.mycompany.business.aspects.SystemArchitecture.inServiceLayer() && !tld.mycompany.business.aspects.SystemArchitecture.publicConstructor()") public Object profileBusiness(ProceedingJoinPoint pjp) throws Throwable { try { long start = System.currentTimeMillis(); String name = pj...

__call magic creating new classes in PHP

Hey everyone, I am using the __call magic within some of my mvc code to produce an autoloadable forms framework but I have ran into a problem I am hoping some one on here might have a work around for. The __call magic takes two paramters: $methodName and $arguments. The arguments come back as an array of args which you called. Normally...

Difference between the different DuplexChannelFactory<TChannel> constructors

Hello =) what is the difference between the three following constructors, and when do i use each of them. sorry for this basic question : DuplexChannelFactory(InstanceContext) DuplexChannelFactory(Object) DuplexChannelFactory(Type) http://msdn.microsoft.com/de-de/library/ms585874.aspx Thanks! regards thomas ...

external side effect in constructor

Look at this code: #include <framework_i_hate.h> int main() { XFile file("./my_file.xxxx", "create"); XObject object("my_object"); // modify the object object.Write(); } Try to guess where object will be saved... yes, you guessed it. I think this is too magic, I'd like to write something like object.Save(file), but it's not n...

Why can't enum constructors be protected or public in Java?

The whole question is in the title. For example: enum enumTest { TYPE1(4.5, "string1"), TYPE2(2.79, "string2"); double num; String st; enumTest(double num, String st) { this.num = num; this.st = st; } } The constructor is fine with the default or private modifier, b...

Moq and constructors - testing initialisation behaviour

I'd like to be able to test a class initialises correctly using Moq: class ClassToTest { public ClassToTest() { Method1(@"C:\myfile.dat") } public virtual void Method1(string filename) { // mock this method File.Create(filename); } } I thought I'd be able to use the CallBase property to...

inserting "this" into an STL map from the constructor

VERSION 1 class Doh { private: static std::map<const std::string, const Doh*> someMap; std::string stringValue_; public: Doh(std::string str) : stringValue_(str) { Doh::someMap.insert( std::make_pair<const std::string,const Doh*> (this->stringValue_,this) ); } } The above wa...

Kohana 3 Controller Constructs

Trying to use __construct inside a controller to assign some variable but it keeps throwing errors. Hoping that someone can lead me in the right direction. class Controller_Mobile extends Controller { public function __construct() { parent::__construct(); $iphoneDetect = strpos($_SERVER['HTTP_USER_AGENT']...

Java: newInstance of class thas has no default constructor

I'm trying to build an automatic testing framework (based on jUnit, but that's no important) for my student's homework. They will have to create constructors of some classes, and add them methods. Then, with the testing functions I provide, they will check if they went allright. What I want to do is, by reflection, create a new instanc...