composition

Liskov Substition and Composition

风流意气都作罢 提交于 2019-11-28 20:52:30
Let say I have a class like this: public sealed class Foo { public void Bar { // Do Bar Stuff } } And I want to extend it to add something beyond what an extension method could do....My only option is composition: public class SuperFoo { private Foo _internalFoo; public SuperFoo() { _internalFoo = new Foo(); } public void Bar() { _internalFoo.Bar(); } public void Baz() { // Do Baz Stuff } } While this works, it is a lot of work...however I still run into a problem: public void AcceptsAFoo(Foo a) I can pass in a Foo here, but not a super Foo, because C# has no idea that SuperFoo truly does

Composing trait behavior in Scala in an Akka receive method

梦想的初衷 提交于 2019-11-28 17:34:00
问题 Consider these two traits: trait Poked extends Actor { override def receive = { case Poke(port, x) => ReceivePoke(port, x) } def ReceivePoke(port: String, x: Any) } trait Peeked extends Actor { override def receive = { case Peek(port) => ReceivePeek(port) } def ReceivePeek(port: String) } Now consider I can create a new Actor that implements both traits: val peekedpoked = actorRef(new Actor extends Poked with Peeked) How do I compose the receive handlers? i.e., the receiver should be

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

狂风中的少年 提交于 2019-11-28 16:33:43
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 general technique for reduction of flicker, what I wondered is, why does it have ANYTHING to do with

C# - Object Composition - Removing Boilerplate Code

為{幸葍}努か 提交于 2019-11-28 15:58:58
问题 Context / Question I've worked on numerous .NET projects that have been required to persist data and have usually ended up using a Repository pattern. Does anyone know of a good strategy for removing as much boilerplate code without sacrificing code base scalability? Inheritance Strategy Because so much of the Repository code is boiler plate and needs to be repeated I normally create a base class to cover the basics like exception handling, logging and transaction support as well as a few

Composition, Inheritance, and Aggregation in JavaScript

巧了我就是萌 提交于 2019-11-28 15:23: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, but list() returns an array with toString() invoked; total() // adds up the stock prices and returns

Application architecture/composition in F#

十年热恋 提交于 2019-11-28 15:13:23
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 can't imagine what an architecture would look like that allows me to work in a similarly flexible fashion

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

拟墨画扇 提交于 2019-11-28 15:05:03
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 collected. Aggregation : My object consists of other objects which can live even after my object is

Multiple inheritance using classes

我与影子孤独终老i 提交于 2019-11-28 13:10:24
Is it possible to extend only some specific part from multiple classes? Example: class Walker { walk() { console.log("I am walking"); } // more functions } class Runner { run() { console.log("I am running"); } // more functions } // Make a class that inherits only the run and walk functions You can pick and choose which methods from other classes you want to add to an existing class as long as your new object has the instance data and methods that the methods you are adding expect to be on that object. class Walker { constructor() {} walk() { console.log("I am walking"); } // more functions }

How to compose functions of varying arity using Lodash flow?

孤街醉人 提交于 2019-11-28 11:47:19
I want to do some function composition. I know already this: If f3(x) shall be the same as f1(f2(x)) then f3 = _.flowRight(f1,f2); If f3(x,y) shall be the same as f1(x, f2(y)) then …? (The use case is the composition of node.js/express middleware functions.) In the following images, I use {_} as a placeholder for a value. Think of it as a hole in the code where we pass something in. Ok let's imagine what your function would have to do... Does this seems like a generic transformation? ie, do you think we can use this in many places? – functional programming promotes building functions which are

How to customize h:head when using ui:composition template?

霸气de小男生 提交于 2019-11-28 09:12:16
I am using JSF to render an HTML page. I design the page like it : <f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="language" content="fr" /> <title><ui:insert name="title">My app</ui:insert></title> </h:head> <h:body> <div id="top"> <ui:include src="/header.xhtml"/> </div> <h:panelGroup id="center" layout="block" > <ui:insert name="center"/> </h