factory

C++ static factory constructor

别等时光非礼了梦想. 提交于 2019-12-10 10:45:06
问题 I am in the process of making a simulation and it requires the creation of multiple, rather similar models. My idea is to have a class called Model and use static factory methods to construct a model. For example; Model::createTriangle or Model::createFromFile . I took this idea from previous java code and was looking for ways to implement this in C++. Here is what I came up with so far: #include <iostream> class Object { int id; public: void print() { std::cout << id << std::endl; } static

What is the right way to implement factory pattern?

风格不统一 提交于 2019-12-10 09:28:07
问题 I just wonder if this is the right way to create objects and implement the factory pattern in PHP. I know we have factory method pattern and Abstract factory pattern, but do we have a pattern like the following http://noondreams.com/shared/data/pages/images/Factory.png ? class Factory { public function make($format) { switch($format) { case Source::Assocs: return new \Source\Formats\Assocs(); case Source::XML return new \Source\Formats\XML(); //Some other formats } } } 回答1: No, this isn't

How to generate tests with different names in TestNG?

怎甘沉沦 提交于 2019-12-10 05:58:49
问题 I'm using TestNG to run Selenium based tests in Java. I have a bunch of repeated tests. Generally, they do all the same except of test name and one parameter. I want to automate generation of it. I was thinking about using factory. Is there a way to generate tests with different name? What would be the best approach to this? As for now I have something like below and I want to create 10 tests like LinkOfInterestIsActiveAfterClick @Test(dependsOnGroups="loggedin") public class SmokeTest

Returning response data from HTTP in Angular factory

霸气de小男生 提交于 2019-12-10 05:42:13
问题 .factory('Api', function($http) { var API = "http://127.0.0.1:4567/"; return { get: function(method) { return $http.get(API + method).success(function(result) { return result; }); } } } Then console.log(Api.get("MAppData")); Returns Object {then: function, success: function, error: function} Why does it not return the result (response data)? 回答1: $http returns a promise and you need to chain .then() to get the data like this: Api.get("MAppData").then(function(response){ var data = response

Why is this factory returning a $$state object instead of response.data?

∥☆過路亽.° 提交于 2019-12-10 03:21:14
问题 So I have a collection of objects in the server I want to populate an ng-repeat when the page loads. I had a made a factory which fetched the list from a resource on the server, like so: app.factory('objectArray', ['$http', function($http) { // This is returning a $$state object // instead of response.data... return $http.post('/get_collection').then(function(response) { console.log(response.data); return response.data; }); }]); I've had this code work before when using ui-router and the

Why does Java Pattern class use a factory method rather than constructor?

岁酱吖の 提交于 2019-12-09 17:58:27
问题 There's a good discussion of this in the general case. However, I was wondering specifically why the Pattern class uses the compile static method to create an object, rather than the constructor? Seems to me to be more intuitive to use a constructor. 回答1: The Pattern class is newer than a lot of the stuff in the JDK. As such I believe they adopted the more modern approach of using factory methods rather than the older approach of public constructors. You can't really retrofit factory methods

Get the parameter prefix in ADO.NET

别来无恙 提交于 2019-12-09 12:53:58
问题 I want to generate several SQL statements based on a column list using the column names as parameters. Edit : C# var columns = new string[] { "COL1", "COL2" }; var tableName = "TABLE_1"; var prefix = "@"; // TODO get this from the provider factory string sqlInsert = string.Format( "INSERT INTO {0}\n( {1}) VALUES\n({2})", tableName, string.Join(", ", columns), string.Join(", ", columns.Select(c => prefix + c))); Generated SQL: INSERT INTO TABLE_1 ( COL1, COL2) VALUES (@COL1, @COL2) This works

Does an IoC container replace the use of Factories

风流意气都作罢 提交于 2019-12-09 05:25:25
问题 I am just getting started with IoC containers so apologies if this is a stupid question. I have code like the following in an app internal static class StaticDataHandlerFactory { public static IStaticDataHandler CreateHandler(StaticDataUpdate staticDataUpdate) { if (staticDataUpdate.Item is StaticDataUpdateOffice) { return new OfficeUpdateHandler(); } if (staticDataUpdate.Item is StaticDataUpdateEmployee) { return new EmployeeUpdateHandler(); } if (staticDataUpdate.Item == null) { throw new

Factory Pattern in C++: generating explicit createInstance()-Method automatically

家住魔仙堡 提交于 2019-12-09 02:14:31
i have the problem in writing a C++ framework, that users should have less overhead than possible to use it. Users can publish their work to the frameworks by creating a shared library that contains a class, which is derived by a frameworks' BaseClass and implementing an extern "C" createInstance()-method in order to return an instance its' derived class. So the framework can access the user class by calling the createInstance-Method through the shared library with dlsym(). class BaseClass{} class UserClass : public BaseClass{} extern "C"{ BaseClass* UserXcreateInstance(){ return new UserClass

multiple $http with promise using factory, angular

倖福魔咒の 提交于 2019-12-08 23:16:38
I am attempting to call multiple $http request in a factory which I Am using to flush out multiple inputs with data and set default selections. I Want to then call a promise once all 3 of these are done to call in the real form data (if there is any, sometimes there will not be in which case it will do nothing) to overwrite the defaults in place. So here is my attempt at this - the factory I set up a factory to call all 3 inputs and their defaults (I am being sent them individually, i cannot change this for now). It looks like this: .factory("getDefaults", function() { return { instructions: