factory

Migration from MBUnit v2 to v3 and the ProviderFactory is gone

醉酒当歌 提交于 2020-01-07 02:25:27
问题 In MBUnit v2 I did this: public class ConnectionStringFactory { [Factory] public string ConnectionString { get { return ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString; } } } [ProviderFactory(typeof(ConnectionStringFactory),typeof(string))] public class CustomerTests { public void GetCustomerTest(string connectionString) { } public void GetCustomersTest(string connectionString) { } } I had to create ONE Factory class returning me a connectionString which gets injected

C++ Smart Factory Design

纵然是瞬间 提交于 2020-01-07 01:29:17
问题 Not c++11 I need to write a Factory in c++ that works like so: 1) The elements created are blocks of objects 2) The factory saves references to all such sub-objects. 3) The blocks are scale-able Meaning: class Block{ MemberType member1; MemberType member2; MemberType member3; Block(){...} } class Factory{ set<MemberType*> members1; set<MemberType*> members2; set<MemberType*> members3; Block& makeBlockInstance(){ Block& currentBlock = *(new Block()); members1.push_back(&(currentBlock.member1))

inject factory data into controller angular.js

纵然是瞬间 提交于 2020-01-06 20:09:42
问题 I am a beginner in angular and dont know how to call factory into controller . Please check my code below. I dont know this is a right way or not. please guide HTML <div class="cart" ng-controller="cartWatch"> <table width="100%"> <tr ng-repeat="pro in item"> <td>Name : {{pro.title}}</td> <td>Quantity : {{pro.quantity}} <input type="text" ng-model="pro.quantity"></input></td> <td>Price : {{pro.price | currency : '&#8377'}}</td> </tr> </table> <div class="total"> total Price : <strong>{

ZF2 Autoloader: Use factory for base class on extended classes as well

纵饮孤独 提交于 2020-01-06 03:59:10
问题 If I wanted to use the same factory for any class that extended my base class, would I want to turn the base class factory into a named function, or is there a better way to do this? $serviceManager => array( 'factories' => array( 'someBaseClass' => function($thisServiceManager) { $db = $thisServiceManager->get('db'); $thisBaseClass = new \myNamespace\thisBaseClass($db); return $thisBaseClass; }, ), ); EDIT Further to the answer I accepted, here's the code I've tested that works. Class File

defaultdict constant_factory doesn't behave as expected

断了今生、忘了曾经 提交于 2020-01-05 05:57:10
问题 I'm willing to use defaultdict with an ad hoc default_factory which suits better my purpose. The default_factory would be [0,0] . I've implemented a constant_factory function: def constant_factory(value): return itertools.repeat(value).next Then when I try to use it, my defaultdict has an unexpected behavior (at least a behavior I didn't expect). Here is an example: >>>import itertools >>>from collections import defaultdict >>>dictio=defaultdict(constant_factory([0,0])) >>>for i in xrange(10)

Can a factory somehow determine all possible classes, by looking in a particular file?

余生长醉 提交于 2020-01-03 05:43:04
问题 Is it possible to create a Factory that generates all derived classes (and class names) at runtime, based on all the classes that are specified in a particular file? For example, given a specific file where users are constantly adding derived classes: class Laptop: public Computer { public: virtual void Run(){mHibernating = false;} virtual void Stop(){mHibernating = true;} private: bool mHibernating; // Whether or not the machine is hibernating }; class Desktop: public Computer { public:

Nice way of factory method pattern with inheritance

守給你的承諾、 提交于 2020-01-02 16:54:40
问题 Suppose I have following class hierarchy: class abstract Parent{} class FirstChild extends Parent {} class SecondChild extends Parent {} And I'd like to create DTO objects from each child: class abstract ParentDTO {} class FirstChildDTO extends ParentDTO{} class SecondChildDTO extends ParentDTO{} I think I need a factory method something like this: ParentDTO createFrom(Parent source); Is there any nice way to do this in Java without instanceof checks and if/else statements? EDIT : This

Is it possible to dynamically create an instance of user-defined Class in Action Script 3?

北城余情 提交于 2020-01-02 09:10:35
问题 I got a factory, where Action Script follows an xml and builds DisplayObject hierarchy out of it. It is meant that script doesn't know beforehand what elements it will encounter in xml and therefore doesn't know what user-defined factory classes it will need. I know that it is possible to do something like this: var rect:*, className:String = "flash.geom.Rectangle"; if (ApplicationDomain.currentDomain.hasDefinition(className)) { rect = new(getDefinitionByName(className)); } And Rectangle

Is it acceptable to return null from a factory constructor in Dart?

安稳与你 提交于 2020-01-02 04:36:06
问题 I've been writing some code in Dart. I really love the factory constructor, but I'm afraid that I'm abusing it's usefulness. In particular, when I write a value object class, I sometimes return null if the validation fails. class EmailAddress { static final RegExp _regex = new RegExp(...); final String _value; factory EmailAddress(String input) { return _regex.hasMatch(input) ? new EmailAddress._internal(input) : null; } const EmailAddress._internal(this._value); toString() => _value; } At

Store JSON data into a variable

无人久伴 提交于 2020-01-02 04:24:07
问题 I am new to AngularJS. I just want to load the JSON file data into a variable that is located in factory. myApp.factory('quizFactory', function () { var questions = [ { "setId":1, "question":"What is the value of the 7 in the following number? 850,765", "options": ["70", "7", "7000", "700"], "answer": 3 }, { "setId":2, "question":"Is 7 & 9 even or odd?", "options": ["Even", "Odd", "Can't Say", "Dont know"], "answer": 1 }, { "setId":3, "question":"In the number 5,281,946 what is the value of