class-design

Overriding class variables in python

可紊 提交于 2021-02-07 05:04:37
问题 I'm trying to understand a bit how Python (2.6) deals with class, instances and so on, and at a certain point, I tried this code: #/usr/bin/python2.6 class Base(object): default = "default value in base" def __init__(self): super(Base, self).__init__() @classmethod def showDefaultValue(cls, defl = default): print "defl == %s" % (defl) class Descend(Base): default = "default value in descend" def __init__(self): super(Descend, self).__init__() if __name__ == "__main__": Descend

Dynamically adding a property to an entity framework object

被刻印的时光 ゝ 提交于 2020-08-03 05:49:13
问题 I have a class like this: public class Empresa { public string Nombre { get; set; } public string NIT { get; set; } public string NombreRepresentanteLegal { get; set; } public string TelefonoRepresentanteLegal { get; set; } public string NombreContacto { get; set; } public string TelefonoContacto { get; set; } } However in my app, I want the users to be able to add custom properties, for example twitter handle, however I havent found documentation in how to do that, I heard about the EAV

classmethod as constructor and inheritance

旧街凉风 提交于 2020-03-01 03:37:48
问题 The problem is quite simple. If a class B inherit a class A and wants to override a ´classmethod´ that is used as a constructor (I guess you call that a "factory method"). The problem is that B.classmethod will want to reuse A.classmethod , but then it will have to create an instance of the class A, while it subclasses the class A - since, as a classmethod, it has no self. And then, it doesn't seem the right way to design that. I did the example trivial, I do more complicate stuff by reading

Any tool which generate C++ code against a design

廉价感情. 提交于 2020-01-23 04:11:17
问题 I have a class diagram , I want that to draw it in some tool which can generate native C++ out of it , I wish to have design first approach to test the various data structures I am designing for my application 回答1: A lot of tools can make C++ code out of UML diagrams. Try Software Ideas Modeller for example, it's a great UML tool, and it's free for non-commercial use. Also, wiki has a list of UML tools. You can sort them by "languages generated" column to check what they do support and chose

Python Class vs. Module Attributes

大兔子大兔子 提交于 2020-01-20 19:17:53
问题 I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around? The problem I have with them, is that it is almost too easy to clobber a class attribute value by mistake, and then your "global" value has turned into a local instance attribute. Feel free to

Python Class vs. Module Attributes

為{幸葍}努か 提交于 2020-01-20 19:17:50
问题 I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around? The problem I have with them, is that it is almost too easy to clobber a class attribute value by mistake, and then your "global" value has turned into a local instance attribute. Feel free to

Using a class' __new__ method as a Factory: __init__ gets called twice

拈花ヽ惹草 提交于 2020-01-19 04:46:27
问题 I encountered a strange bug in python where using the __new__ method of a class as a factory would lead to the __init__ method of the instantiated class to be called twice. The idea was originally to use the __new__ method of the mother class to return a specific instance of one of her children depending on the parameters that are passed, without having to declare a factory function outside of the class. I know that using a factory function would be the best design-pattern to use here, but

.NET ORMs, immutable value objects, structs, default constructors, and readonly properties

喜欢而已 提交于 2020-01-12 18:47:20
问题 I am just getting started with .NET ORMs, to the point where I haven't even decided between Entity Framework and NHibernate. But in both cases, I'm running into a problem in that they seem to want me to compromise the integrity of my domain model in various ways, especially on finer points of C# object design. This is one of several questions on the subject. I am very used to enforcing immutability on appropriate properties with a pattern that looks like this: public class Foo { private