composition

Is there a model MultiField (any way to compose db models Fields in Django)? Or why would not that be a useful concept?

血红的双手。 提交于 2019-12-01 10:11:25
问题 When building a Django application, we were exposed to (forms) MultiValueField and MultiWidget . They seem like an interesting approach to compose their respective base classes, giving more modularity. Yet, now it seems to us that the actual piece that would make those two shine bright would be a db.models.MultiField . Here is the reasoning: It seems that, when using a ModelForm, Django is enforcing a strict 1-to-1 association between a models.Field and a forms.Field. Now, with forms

Creating multiple (15+) HTTP Response filters, Inheritance vs. Composition w/ Injection

泄露秘密 提交于 2019-12-01 09:19:36
问题 First a little back story on what I am trying to accomplish. I am in the process of creating a custom HTTP Module whose purposes is to intercept messages to multiple (15+) different ArcGIS REST web services. The intercepted requests and/or responses will be stripped of any restricted information based on the current user. For instance, a call that returns multiple layers might have certain layers stripped out. Unmodified Response: "layers" : [ { "id" : 0, "name" : "Facilities", "parentLayerId

Should I extend an ArrayList (is-a) or should I include it as a member (has-a)?

徘徊边缘 提交于 2019-12-01 05:20:20
I'm making a simple program that maintains a list of numbers, and I want this list to also have a name. Which is the best approach: have my list class extend ArrayList or have it include an ArrayList member? In both cases, there would of course be a "name" String member. The first approach means I only have to implement a getter & setter for the name, but I think this would tie my class too closely to a particular implementation? For example, if I wanted to later use a Vector, than I would have to change code everywhere. The second approach would make it easier to change the implementation,

Aggregation and Composition in Java Code

此生再无相见时 提交于 2019-12-01 00:43:24
As the Aggregation and Composition is related Association or we can say it gives the understanding of relationship between object or anything else. I posted this question because i asked one question in Interview that what is the Composition and Aggregation. So as per my understanding i given my idea which is as follow. http://www.coderanch.com/t/522414/java/java/Association-Aggregation-Composition Aggregation, Association and Composition Association vs. Aggregation vs. Composition in Java and also visited much more. and my basic explanation was related that Aggregation indicates loose

Aggregation and Composition in Java Code

一曲冷凌霜 提交于 2019-11-30 19:47:38
问题 As the Aggregation and Composition is related Association or we can say it gives the understanding of relationship between object or anything else. I posted this question because i asked one question in Interview that what is the Composition and Aggregation. So as per my understanding i given my idea which is as follow. http://www.coderanch.com/t/522414/java/java/Association-Aggregation-Composition Aggregation, Association and Composition Association vs. Aggregation vs. Composition in Java

How does class composition work in iOS?

半世苍凉 提交于 2019-11-30 11:24:20
Let's say I have property A on classA and property B on classB and I want classAB to have both properties A and B . I still don't understand how to make this all work with composition . I realize this can be done with inheritance, but I want to learn how to do this with composition . I've looked at examples and I still don't get how it all works. You make a new class, which has instances of classA and classB as member variables. Then you implement the properties by passing through the get/set methods. @interface ClassAB { ClassA *objectA; ClassB *objectB; } @property (nonatomic,strong) id

Locate the correct composition root for a .NET library

﹥>﹥吖頭↗ 提交于 2019-11-30 09:23:27
I've read various other question here on the argument, most notably Dependency Inject (DI) “friendly” library Ioc/DI - Why do I have to reference all layers/assemblies in entry application? and this article (and other various material). However it's not clear to me where to place composition root in library (DLL) .NET project. The project does not belong to any specific type mentioned in the article. In desktop, console or even web application this point is instead clearly defined. My current approach is to wrap the container, register types and re-expose the Resolve method: class

Composition vs Inheritance in MVP

我怕爱的太早我们不能终老 提交于 2019-11-30 04:45:37
I'm using MVP pattern to develop a large scale application. While working in the development I have come up with the question whether if composition or inheritance should be used. For example: Let's assume that I have a form called Foo with fields A and B . In other part of the application I have a form Bar that has the same fields A and B but an additional field C . Currently, the code is written with the inheritance approach in where the view the form Bar inherits from form Foo . The presenters then handle the data a little different with the model. This works out pretty simply but beats me

why inheritance is strongly coupled where as composition is loosely coupled in Java? [duplicate]

巧了我就是萌 提交于 2019-11-30 03:54:10
This question already has an answer here: Prefer composition over inheritance? 32 answers I have heard this favor composition over inheritance again and again in design patterns. some of the reasons cited for this are 1)Inheritance is strongly coupled where as composition is loosely coupled 2) Inheritance is compile time determined where as composition is run-time 3)Inheritance breaks encapsulation where as composition does not 4) anything else I am not aware of It would be great for beginners like to me follow these by illustrations as how inheritance and composition differs with respect to

inheritance vs. composition for testability

只谈情不闲聊 提交于 2019-11-30 03:27:33
While designing my objects I find composition to be a better choice from the perspective of testability. The reason being, I can mock parts of the composition structure if I need to, while running unit tests. This is not possible if I have an inheritance hierarchy. I would like to know if others have also found this to be a reason to prefer composition. Also what other testability pitfalls did you get into because inheritance was used? I believe that the more you start to develop using design patterns, you'll find more and more often where composition is going to be favored over inheritance. I