factory

Dynamic Python Class Definition in SQLAlchemy

风流意气都作罢 提交于 2019-12-11 01:58:17
问题 I'm creating a backend application with SQLAlchemy using the declarative base. The ORM requires about 15 tables each of which maps to a class object in SQLAlchemy. Because these class objects are all defined identically I thought a factory pattern could produce the classes more concisely. However, these classes not only have to be defined, they have to be assigned to unique variable names so they can be imported and used through the project. (Sorry if this question is a bit long, I updated it

Python deep nesting factory functions

六眼飞鱼酱① 提交于 2019-12-10 23:13:53
问题 Working through "Learning Python" came across factory function. This textbook example works: def maker(N): def action(X): return X ** N return action >>> maker(2) <function action at 0x7f9087f008c0> >>> o = maker(2) >>> o(3) 8 >>> maker(2) <function action at 0x7f9087f00230> >>> maker(2)(3) 8 However when going deeper another level I have no idea how to call it: >>> def superfunc(X): ... def func(Y): ... def subfunc(Z): ... return X + Y + Z ... return func ... >>> superfunc() Traceback (most

How to use a factory to create objects which use Strategy pattern?

試著忘記壹切 提交于 2019-12-10 19:12:13
问题 Let's assume we have a simple payment feature on an online shop. We want to manage different transactions with different processors of transactions: A transaction can be a payment or a refund. A processor of transactions can be Paypal or Payplug. So we have the following classes: class PaymentTransaction implements Transaction { } class RefundTransaction implements Transaction { } class PaypalProcessor implements Processor { } class PayplugProcessor implements Processor { } As suggested in

How to destroy an angular factory instance

别等时光非礼了梦想. 提交于 2019-12-10 17:15:57
问题 On the one hand, I have several factories where each factory controls a websocket. On the other hand, One of those factories should be started when client is logged, so: if(user.isLogged()){ $injector.get('NotificationsWebsocket') } That's the way I initialize my factory dinamically, the problem come up when the user logs out. I don't know how to delete an instance of angular instances factory or how to destroy the NotificationsWebsocket. I tried to close socket, but when I log in again, the

How to register a new payum payment method and add actions?

邮差的信 提交于 2019-12-10 16:48:03
问题 I have created a payum payment method. I have set up a payment form that stores the payment details and then I generate the payment security token. This all seems ok so far and payum generates the token in storage. However, I cannot seem to register it. I don't know where I am supposed to add the actions so they are used when payment method is loaded. I have the following questions. Where do I add a reference to my PaymentFactory? At the moment I load the payum extension in the bundle build

How to write generic factory method in swift?

隐身守侯 提交于 2019-12-10 15:07:22
问题 I am not sure how to, if it's possible to, write method that calls constructor of it's generic type inheriting from common known base class < T:Base > to create some instances of T without resorting to explicit factory function i.e. with all bells and whistles provided by type inference. Example that works in playground: // Let there be classes MyPod and Boomstick with common Base (not important) class Base : Printable { let value : String; init(_ value : String) { self.value = "Base." +

Blocking the possibility to create classes directly bypassing a factory

限于喜欢 提交于 2019-12-10 14:43:31
问题 In a base class for all the models in our MVC system, I created a factory method BaseCLass::getNew() that returns an instance of the requested child class when called via SomeChildClass::getNew(). Now, I'm looking for a way to force the programmer to use this factory. I.e., idially I'd like that any class created directly, like this: new SomeChildClass will throw an exception upon creation, and only classes created by the factory will be usable. Any ideas how can this be achieved? Our code is

C++ instantiate templates in loop

淺唱寂寞╮ 提交于 2019-12-10 14:34:43
问题 I have have a factory class, which needs to instantiate several templates with consecutive template parameters which are simple integers. How can I instantiate such template functions without unrolling the entire loop? The only thing that can think of is using boost pre-processor. Can you recommend something else, which does not depend on the preprocessor? thanks 回答1: Template parameters have to be compile-time constant. Currently no compiler considers a loop counter variable to be a constant

Force Singleton Pattern on a Class implementing an Interface

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 13:54:59
问题 I better explain the question with an example. I have an Interface Model which can be used to access data. There can be different implementations of Model which can represent the data in various format say XMl , txt format etc. Model is not concerned with the formats. Lets say one such implementation is myxmlModel . Now i want to force myxmlModel and every other implementation of Model to follow Singleton Pattern .The usual way is to make myxmlModels constructor private and provide a static

Passing a class as a parameter of a procedure in Delphi XE

微笑、不失礼 提交于 2019-12-10 13:25:31
问题 what i need to do is something like this: procedure A(type_of_form); var form: TForm; begin form := type_of_form.Create(application); form.showmodal; freeandnil(form); end; I did this for every dynamically created form: form1 := TForm1.Create(application); form1.showmodal; freeandnil(form1); What i will do inside procedure A is more complex, but the problem resides in how to make the creation of the form somewhat general. Perhaps something with @ operator... i really do not know. Thanks for