factory

What is a name for a pattern where it receives data or asks for data and returns back an object?

对着背影说爱祢 提交于 2019-12-12 06:26:56
问题 Question 1 Is there a name for the pattern below? class Pattern { function createObject(array $data) { $object = new Object(); $object->setPropertyA($data['A']); $object->setPropertyB($data['B']); $object->setPropertyC($data['C']); return $object; } } Question 2 Is there a name for the above pattern if it is altered to where $data is acquired inside the method? Specifically code below: class Pattern2 { function createObject() { $data = $this->service->acquireData(); $object = new Object();

C# Dependency Injection passing additional parameter

此生再无相见时 提交于 2019-12-12 06:12:39
问题 I have a class similar to the following: public class CarAttributes { private readonly ICarRepository _carRepository; private readonly int _carId; public CarAttributes(ICarRepository carRepository, int carId) { _carRepository = carRepository; _carId = carId; } public bool IsRegistered { get { return _carRepository.IsRegistered(_carId); } } public bool IsStolen { get { return _carRepository.IsStolen(_carId); } } } I also have the following method (which is syntactically incorrect) public

Globally injecting am AngularJS factory mockup when testing with Jasmine

点点圈 提交于 2019-12-12 04:34:33
问题 I'm creating unit tests for my AngularJS application's controllers. In myapp.run I'm injecting and using a factory, called UsersFactory, somehow like this: myApp.run(['$rootScope','UsersFactory', function ($rootScope,UsersFactory) { UsersFactory.getMe().then(function(data) { //.. }); }]); I created a Mock for UsersFactory called UsersFactoryMock. It has the same methods as UsersFactory, but the implementation is different (fake) of course. I would like to inject UsersFactoryMock, in order to

Can I derive from a class that can only be created by a “factory”?

回眸只為那壹抹淺笑 提交于 2019-12-12 03:42:57
问题 Suppose that a library I'm using implements a class class Base(object): def __init__(self, private_API_args): ... It's meant to be instantiated only via def factory(public_API_args): """ Returns a Base object """ ... I'd like to extend the Base class by adding a couple of methods to it: class Derived(Base): def foo(self): ... def bar(self): ... Is it possible to initialize Derived without calling the private API though? In other words, what should be my replacement for the factory function?

How to override static, factory-like method in subclasses

荒凉一梦 提交于 2019-12-12 01:53:47
问题 PROBLEM: Static methods from a base class cannot be overriden, so I cannot compile this code (if I could, my design would be solved): public abstract class ParametersBase { public static abstract ParametersBase CreateDefault(); // THIS DOES NOT COMPILE! } public abstract class ParametersXml<T> where T : ParametersBase { public static T LoadOrDefault(string fname) { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; T result; var

Angular - pass info from array from one controller to another

一世执手 提交于 2019-12-12 01:36:35
问题 I'm having a little problem trying to pass a service within controllers. What I'm trying to do is a shopping cart, I have a list of items and when I hit a button, those items get added to the cart, then I want to list those items in the cart in a separate page using a separate controller, so I'm trying to use a factory for the cart, but I don't know if you can set a factory object within a controller. Here's my code, hope you can point me in the right direction. var app = angular.module("Shop

Implementing custom factory pattern in Spring

隐身守侯 提交于 2019-12-12 00:27:20
问题 Normally if I want to implement a factory pattern I will do it like this. public class CustomFactory(){ // pay attention: parameter is not a string public MyService getMyService(Object obj){ /* depending on different combinations of fields in an obj the return type will be MyServiceOne, MyServiceTwo, MyServiceThree */ } } MyServiceOne, MyServiceTwo, MyServiceThree are implementations of the interface MyService. That will work perfectly fine. But the issue is that I would like to have my

Load json data into the factory file

旧街凉风 提交于 2019-12-11 23:33:53
问题 I am new to AngularJS and just started learning it. How can I load the JSON file into the script.js file without directly adding the entire data. Here is the code of the program: <!DOCTYPE html> <html ng-app="quizApp"> <head> <meta charset="utf-8" /> <title>QuizApp</title> <link rel="stylesheet" href="style.css" /> <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script> <script src="script

Add eObject to the parse tree programaticaly

烂漫一生 提交于 2019-12-11 22:23:23
问题 Here is a snapshot of my grammar: Sort: name=ID ; Variable name=ID ':' type=[Sort] My requirement is to have a predefined Sort let's call it Loc . There is no need for the user to define this sort, thus when a Variable is defined with a Loc type, Xtext should automatically reference it to my predefined Sort. How can I initiate the program so that at the beginning a Sort instance is generated? I already used the Factory method 'CreateSort' in my validator class, but no use. any idea? 回答1: Your

Angular application name not identified

血红的双手。 提交于 2019-12-11 20:15:23
问题 I'm trying to define a factory for DB access using the following sample code: MyApp.service("DB_Services", [ "$http" , function($http) { DB_Services.Get_Data_from_DB_Internal = function (p_Request) { var http = new XMLHttpRequest(); var url = "http://localhost/servlet/Test_ui"; var params = "data=" + p_Request ; http.open("POST", url, true); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); if(http