composition

Difference between trait inheritance and self type annotation

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:43:53
In Scala, I've seen the constructs trait T extends S and trait T { this: S => used to achieve similar things (namely that the abstract methods in S must be defined before an instance may be created). What's the difference between them? Why would you use one over the other? I'd use self-types for dependency-management: This trait requires another trait to be mixed in. And I'd use inheritance to refine another trait or interface. Just as an example: trait FooService trait FooRemoting { this : FooService => } trait FooPersistence { this : FooService => } object Services extends FooService with

“Is a” vs “Has a” : which one is better?

我与影子孤独终老i 提交于 2019-11-28 04:47:35
Portfolio A → Fund 1 Portfolio A → Fund 2 Portfolio A → Fund 3 I couldn't frame my sentence without not using is/has. But between 1 & 2, 1) has a: class PortfolioA { List<Fund> obj; } 2) is a: class PortfolioA : List<Fund> { } which one do you think is better from the point of extensibility, usability? I can still access my funds either way, albeit with a small syntactical change. I vote with the other folks who say HAS-A is better in this case. You ask in a comment: when I say that a Portfolio is just a collection of funds, with a few attributes of its own like TotalPortfolio etc, does that

Component which dependent from other components with different scopes (component hierarchies with different scopes)

此生再无相见时 提交于 2019-11-28 04:41:50
问题 I have complex multi-tier architecture in my Android project. Currently i want to use the following structure of the DI components and modules: [Data Layer] @DataScope //scope is used for caching (Singleton) some Data Layer entities for whole application - DataComponent //exposes just interfaces which should be used on the BL Layer //Modules exposes entities for internal (Data Layer) injections and entities which exposed by DataComponent for BL Layer * DataModule1 * DataModule2 * DataModule3

Haskell composition (.) vs F#'s pipe forward operator (|>)

会有一股神秘感。 提交于 2019-11-28 02:53:32
In F#, use of the the pipe-forward operator, |> , is pretty common. However, in Haskell I've only ever seen function composition, (.) , being used. I understand that they are related , but is there a language reason that pipe-forward isn't used in Haskell or is it something else? Brian I am being a little speculative... Culture : I think |> is an important operator in the F# "culture", and perhaps similarly with . for Haskell. F# has a function composition operator << but I think the F# community tends to use points-free style less than the Haskell community. Language differences : I don't

Aggregation vs Composition vs Association vs Direct Association

旧城冷巷雨未停 提交于 2019-11-28 02:47:48
I am reviewing my knowledge in object-oriented programming. Under the relationship between classes topic, I have encountered some relationships which are a bit ambiguous to me. I know dependency "uses-a" and inheritance "is-a" but I'm a bit unfamiliar with Aggregation, Composition, Association and Direct Association; also, which of them is "has-a" relationship. Some use Aggregation interchangeably with Association. What is Direct Association? Also, what is Composition? In UML diagrams, the arrows that represents them are different. I would be really thankful if you could clear these things out

Compostions and mixins in JS

只谈情不闲聊 提交于 2019-11-28 01:40:38
I got some trouble with compostions and mixin . For examples, lets imagine that we have a AHero and Hero1 object. All heroes can move, so AHero.move() is a thing. And now, at a moment of the dev, I want to add the possibility to stun and beStunned. So I make a new object that look like this ( called stunTrait) : { stunned : false, stun(), beStun, } And I decide to give to possiblity to heroes to stun and beStunned. So I do a mixin : class AHero extends stunTrait(superclass). Now I want that a stunned hero can not move. So in Ahero : move(){ if(this.stunned) return; ... } Later I find out stun

Method forwarding with composition instead of inheritance (using C++ traits)

时光毁灭记忆、已成空白 提交于 2019-11-28 01:25:42
问题 I would like to use composition and to write good forwarding methods for every possible overload (noexcept, const, volatile) using C++ capabilities. The idea is to use traits in order to determine whether a method is declared {noexcept / const / volatile / etc.} and to behave accordingly. Here is an example of what I would like to achieve : struct User{ UsedObject& obj; User(UsedObject& obj) : obj(obj) {} FORWARD_METHOD(obj, get); //here is where the forwarding happens }; struct UsedObject{

Python: Inheritance versus Composition

徘徊边缘 提交于 2019-11-27 21:28:53
I am working with two classes in Python, one of which should be allowed to have any number objects from another class as children while keeping an inventory of these children as an attribute. Inheritance seemed like the obvious choice for this parent<>child situation but instead what I have arrived at is an example of composition. Here is the simplified code: class Parent(): def __init__(self,firstname,lastname): self.firstname = firstname self.lastname = lastname self.kids = [] def havechild(self,firstname): print self.firstname,"is having a child" self.kids.append(Child(self,firstname))

Application architecture/composition in F#

﹥>﹥吖頭↗ 提交于 2019-11-27 19:44:13
问题 I have been doing SOLID in C# to a pretty extreme level in recent times and at some point realized I'm essentially not doing much else than composing functions nowadays. And after I recently started looking at F# again, I figured that it would probably be the much more appropriate choice of language for much of what I'm doing now, so I'd like to try and port a real world C# project to F# as a proof of concept. I think I could pull off the actual code (in a very un-idiomatic fashion), but I

UML association vs. composition and detail level

爱⌒轻易说出口 提交于 2019-11-27 18:24:23
Actually, make that a couple of amateur UML questions! When creating a UML diagram to model some domain concepts and you come across a domain concept that "holds" some information about another concept, is it better to hold a stamp/reference to that entity or hold the whole entity in the model itself? Please bear in mind that this is relating to creating a simple high-level model - I'm sure in the implementation stage things would be slightly different. For example, which of the two models below is actually correct? The first one has a composition relationship, with FlightBooking holding the