composition

Composing trait behavior in Scala in an Akka receive method

一个人想着一个人 提交于 2019-11-29 21:47: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 something like the following code, though "automatically generated" (i.e., all traits should compose): def

C# - Object Composition - Removing Boilerplate Code

空扰寡人 提交于 2019-11-29 20:10:25
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 basic CRUD methods: public abstract class BaseRepository<T> where T : IEntity { protected void

How does class composition work in iOS?

孤者浪人 提交于 2019-11-29 16:38:11
问题 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. 回答1: You make a new class, which has instances of classA and classB as member variables. Then you implement the properties by passing through the

Locate the correct composition root for a .NET library

纵饮孤独 提交于 2019-11-29 14:13:12
问题 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

Can inheritance be replaced completely by composition?

守給你的承諾、 提交于 2019-11-29 09:17:26
问题 This question is NOT question like "inheritence vs composition". I understand completely how inheritance differs from composition, I know the Liskov substitution principle, the diamond problem, advantages and disadvantages both of them and both concepts seem to be simple. But there is so many questions everywhere about inheritance and composition, that i thought, maybe I misunderstand something in this simple idea. Lets focus on Go. Go is a language from Google and everybody is excited it has

What is the difference between UIView and UIViewController?

陌路散爱 提交于 2019-11-29 08:03:31
I need a detailed explanation on the following: What do we use a UIViewController for? What is the use of it? I have a class that looks like the following: class one { UINavigationController *nav = ...; two *secondObject = ...; // By use of it, I have push the new view class two//ok } class two { ... } How can I use secondObject in the class one ? What is the class hierarchical start from the window? Erik The UIViewController is the controller part in the MVC design pattern. Model <-------> Controller <-------> View The controller's task is to handle navigation between different views, key

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

你说的曾经没有我的故事 提交于 2019-11-29 07:35:07
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{ string m{"Hello\n"}; string& get(double d){ cout << "\tUsed :const not called...\n"; return m; } const

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

隐身守侯 提交于 2019-11-29 01:30:08
问题 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

UML Notation - Aggregations/Compositions vs “Vanilla” Associations

我只是一个虾纸丫 提交于 2019-11-29 00:14:34
I've recently spent a good deal of time performing detailed UML designs of various SW components that I have since written. Looking back on what I have recently finished and comparing that to when I first learned UML, I see that I now almost strictly use Aggregation and Composition relationships, and have virtually abandoned "vanilla" non-directed/directed relationships. I still of course use Generalizations and Realizations, but these are distinctly different than those above and are not considered part of this question. It seems to me that Aggregation/Composition implies the same meaning of

inheritance vs. composition for testability

谁说胖子不能爱 提交于 2019-11-28 22:23:23
问题 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? 回答1: I believe that the more you start to develop using