composition

Mixins for ES6 classes, transpiled with babel

早过忘川 提交于 2019-11-26 22:30:38
According to various sources ( 2ality , esdiscuss ) one should be able to add mixins to classes: EDIT discovered that class methods are not enumerable so that cannot work. Edited the code below, but still no joy class CartoonCharacter { constructor(author) { this.author = author; } drawnBy() { console.log("drawn by", this.author); } } // THIS CANNOT WORK // class methods are not enumerable // class Human { // haveFun() { // console.log("drinking beer"); // } // } let Human = Object.create({}, { haveFun: { enumerable: true, value: function () { console.log("drinking beer"); } } }); class

Compostions and mixins in JS

陌路散爱 提交于 2019-11-26 21:58:49
问题 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

Composing functions in python

血红的双手。 提交于 2019-11-26 20:22:10
I have an array of functions and I'm trying to produce one function which consists of the composition of the elements in my array. My approach is: def compose(list): if len(list) == 1: return lambda x:list[0](x) list.reverse() final=lambda x:x for f in list: final=lambda x:f(final(x)) return final This method doesn't seems to be working, help will be appreciated. (I'm reversing the list because this is the order of composition I want the functions to be) It doesn't work because all the anonymous functions you create in the loop refer to the same loop variable and therefore share its final

UML association vs. composition and detail level

北城以北 提交于 2019-11-26 19:25:08
问题 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

Is there anything composition cannot accomplish that inheritance can?

爷,独闯天下 提交于 2019-11-26 19:24:39
问题 Composition and inheritance. I am aware that they are both tools to be chosen when appropriate, and context is very important in choosing between composition and inheritance. However, the discussion about the appropriate context for each is usually a little fuzzy; this has me beginning to consider just how distinctly inheritance and polymorphism are separate aspects of traditional OOP. Polymorphism allows one to specify "is-a" relationships equally as well as inheritance. Particularly,

React.js: Wrapping one component into another

微笑、不失礼 提交于 2019-11-26 18:43:45
问题 Many template languages have "slots" or "yield" statements, that allow to do some sort of inversion of control to wrap one template inside of another. Angular has "transclude" option. Rails has yield statement. If React.js had yield statement, it would look like this: var Wrapper = React.createClass({ render: function() { return ( <div className="wrapper"> before <yield/> after </div> ); } }); var Main = React.createClass({ render: function() { return ( <Wrapper><h1>content</h1></Wrapper> );

Orchestration vs. Choreography

给你一囗甜甜゛ 提交于 2019-11-26 18:43:07
问题 What are the differences between service orchestration and service choreography from an intra-organization point of view. 回答1: Basic technologies such as (XML, SOAP, WSDL) provide means to describe, locate, and invoke services as an entity in its own right. However, these technologies do not give a rich behavioral detail about the role of the service in more complex collaboration. This collaboration includes a sequence of activities and relationships between activities, which build the

Why use inheritance at all? [closed]

故事扮演 提交于 2019-11-26 18:26:58
I know the question has been discussed before , but it seems always under the assumption that inheritance is at least sometimes preferable to composition. I'd like to challenge that assumption in hopes of gaining some understanding. My question is this: Since you can accomplish anything with object composition that you can with classical inheritance and since classical inheritance is very often abused[1] and since object composition gives you flexibility to change the delegate object runtime, why the would you ever use classical inheritance? I can sort of understand why you would recommend

When to use C++ private inheritance over composition?

一个人想着一个人 提交于 2019-11-26 17:49:04
问题 Can you give me a concrete example when is preferable to use private inheritance over composition? Personally, I will use composition over private inheritance, but there might be the case that using private inheritance is the best solution for a particular problem. Reading the C++ faq, gives you an example on using private inheritance, but I seems easier to use composition + strategy pattern or even public inheritance than private inheritance. 回答1: private inheritance is typically used to

Avoiding duplicate ids when reusing facelets compositions in the same naming container

谁说胖子不能爱 提交于 2019-11-26 17:45:36
I have a <ui:composition> that contains a few elements with explicit ids and some ajax events which reference these ids for partial processing/updating. I encapsulated this fragment of xhtml inside the composition simply so I could use it in a few different places without having to duplicate the code. However, when I use the composition (with <ui:include> ) more than once inside a page, I get duplicate id exceptions. It seems JSF is not wrapping each composition inside its own naming container (like <ui:component> does). Is there a simple way to wrap my composition inside its own naming