class-factory

Python - how do I force the use of a factory method to instantiate an object?

半世苍凉 提交于 2020-01-04 13:16:50
问题 I have a set of related classes that all inherit from one base class. I would like to use a factory method to instantiate objects for these classes. I want to do this because then I can store the objects in a dictionary keyed by the class name before returning the object to the caller. Then if there is a request for an object of a particular class, I can check to see whether one already exists in my dictionary. If not, I'll instantiate it and add it to the dictionary. If so, then I'll return

Class factory to produce simple struct-like classes?

邮差的信 提交于 2019-12-17 22:34:37
问题 While investigating Ruby I came across this to create a simple Struct-like class: Person = Struct.new(:forname, :surname) person1 = Person.new('John', 'Doe') puts person1 #<struct Person forname="John", surname="Doe"> Which raised a few Python questions for me. I have written a [VERY] basic clone of this mechanism in Python: def Struct(*args): class NewStruct: def __init__(self): for arg in args: self.__dict__[arg] = None return NewStruct >>> Person = Struct('forename', 'surname') >>> person1

Custom COM class factory for managed in-proc server

假装没事ソ 提交于 2019-12-07 17:22:20
问题 I'm looking at implementing custom COM activation logic for a managed class library, in MkParseDisplayName/BindToObject manner. This way, creating an object from VB might look like this: obj = GetObject("clsid:12341234-1234-1234-1234-123412341234:!UniqueObjectId") That would not be a problem for an out-of-proc server (using CoRegisterClassObject ). However, for an in-proc server, I'd need to alter the implementation of DllGetClassObject , which is normally provided by mscoree.dll . Is this

Custom COM class factory for managed in-proc server

馋奶兔 提交于 2019-12-06 03:01:15
I'm looking at implementing custom COM activation logic for a managed class library, in MkParseDisplayName/BindToObject manner . This way, creating an object from VB might look like this: obj = GetObject("clsid:12341234-1234-1234-1234-123412341234:!UniqueObjectId") That would not be a problem for an out-of-proc server (using CoRegisterClassObject ). However, for an in-proc server, I'd need to alter the implementation of DllGetClassObject , which is normally provided by mscoree.dll . Is this possible at all? The only other option I see is to create a C# singleton object to serve as class

Class factory to produce simple struct-like classes?

喜你入骨 提交于 2019-11-28 18:01:55
While investigating Ruby I came across this to create a simple Struct-like class: Person = Struct.new(:forname, :surname) person1 = Person.new('John', 'Doe') puts person1 #<struct Person forname="John", surname="Doe"> Which raised a few Python questions for me. I have written a [VERY] basic clone of this mechanism in Python: def Struct(*args): class NewStruct: def __init__(self): for arg in args: self.__dict__[arg] = None return NewStruct >>> Person = Struct('forename', 'surname') >>> person1 = Person() >>> person2 = Person() >>> person1.forename, person1.surname = 'John','Doe' >>> person2