composition

Is there anything composition cannot accomplish that inheritance can?

﹥>﹥吖頭↗ 提交于 2019-11-27 18:23:01
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, inheriting from a base class implicitly creates a polymorphic relationship between that class and its

React.js: Wrapping one component into another

眉间皱痕 提交于 2019-11-27 16:40:42
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> ); } }); Desired output: <div class="wrapper"> before <h1>content</h1> after </div> Alas, React.js doesn

Orchestration vs. Choreography

落花浮王杯 提交于 2019-11-27 16:38:36
What are the differences between service orchestration and service choreography from an intra-organization point of view. 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 business process. There are two ways to build this process: service orchestration and service choreography.

Refactoring legacy mixin-based class hierarchies

▼魔方 西西 提交于 2019-11-27 15:54:35
I'm currently working on a huge javascript project which has a huge class hierarchy and heavily uses mixins to extend functionality of base classes. Here is an example of how mixin looks like, we're using compose library to create class-like objects: // Base.js var Base = compose({ setX: function (x) { this.x = x; }, setY: function (y) { this.y = y; }, setPosition: function (x, y) { this.setX(x); this.setY(y); } }) // SameXAndY.js - mixin var SameXAndY = compose({ // Executes after setX in Base.js setX: compose.after(function (x) { this.y = x; }), // Executes after setY in Base.js setY:

Ensuring embedded structs implement interface without introducing ambiguity

﹥>﹥吖頭↗ 提交于 2019-11-27 15:25:13
I'm trying to clean up my code base by doing a better job defining interfaces and using embedded structs to reuse functionality. In my case I have many entity types that can be linked to various objects. I want to define interfaces that capture the requirements and structs that implement the interfaces which can then be embedded into the entities. // All entities implement this interface type Entity interface { Identifier() Type() } // Interface for entities that can link Foos type FooLinker interface { LinkFoo() } type FooLinkerEntity struct { Foo []*Foo } func (f *FooLinkerEntity) LinkFoo()

Object Oriented Best Practices - Inheritance v Composition v Interfaces

放肆的年华 提交于 2019-11-27 10:34:15
I want to ask a question about how you would approach a simple object-oriented design problem. I have a few ideas of my own about what the best way of tackling this scenario, but I would be interested in hearing some opinions from the Stack Overflow community. Links to relevant online articles are also appreciated. I'm using C#, but the question is not language specific. Suppose I am writing a video store application whose database has a Person table, with PersonId , Name , DateOfBirth and Address fields. It also has a Staff table, which has a link to a PersonId , and a Customer table which

Delphi support for Aero Glass and the DoubleBuffered property - what is going on and how do we use them?

∥☆過路亽.° 提交于 2019-11-27 09:46:52
问题 I am confused by Delphi 2009/2010 support for the Aero Theme Glass features in Windows, and by what, exactly DoubleBuffered means, and what it has to do with Aero glass. I have found that DoubleBuffered is not only a property in the VCL, it also is found in .net WinForms. Initially I wondered if it set some kind of window style bit used by the common controls library, or what. Why is it used, and when should it be used? [Update: I should state that I know what "double-buffering" is, as a

When to use C++ private inheritance over composition?

ⅰ亾dé卋堺 提交于 2019-11-27 09:15:29
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. private inheritance is typically used to represent "implemented-in-terms-of". The main use I have seen is for mixins using private multiple inheritance

Composition, Inheritance, and Aggregation in JavaScript

那年仲夏 提交于 2019-11-27 09:11:01
问题 There is a lot of information about composition vs inheritance online, but I haven't found decent examples with JavaScript. Using the below code to demonstrate inheritance: function Stock( /* object with stock names and prices */ ) { for (var company_name in arguments[0]) { // copy the passed object into the new object created by the constructor this[company_name] = arguments[0][company_name]; } } // example methods in prototype, their implementation is probably redundant for // this question

Distinguishing between delegation, composition and aggregation (Java OO Design)

谁说胖子不能爱 提交于 2019-11-27 08:59:38
问题 I am facing a continuing problem distinguishing delegation, composition and aggregation from each other, and identifying the cases where it's the best to use one over the other. I have consulted a Java OO Analysis and Design book, but my confusion still remains. The main explanation is this: Delegation : When my object uses another object's functionality as is without changing it. Composition : My object consists of other objects which in turn cannot exist after my object is destroyed-garbage