composition

Using MEF with abstract base class

喜你入骨 提交于 2019-12-12 02:26:06
问题 I'm building a database import app than I want to be extensible (custom db models can be added as needed). My base component has methods that extended types have to implement: MapData & SaveData. I defined the base as an abstract class, and everything works when the extended types are in the same namespace. However, I want to use MEF to import extended types in a different namespace at runtime, but I can't figure out how to do that. Base class: namespace Program { public abstract class

Php reading object variable as part of other variable

筅森魡賤 提交于 2019-12-12 01:41:45
问题 I have an array structure of 60 elements. I'd like to use a for/foreach/while to read this structure. This is what I have : $this->details->field_link_01[0]['title'] $this->details->field_link_02[0]['title'] .. $this->details->field_link_60[0]['title'] And what i need is the following. $myvar = eval ( "$this->details->field_link_" . $cont . "[0]['title']" ) What I have seen is PHP let to use $ as evaluation function $myvar = ${"this->details->field_link_" . $cont . "[0]['title']" } But it

C++ Object Composition, Depdendency Injection and Copy Constructors

被刻印的时光 ゝ 提交于 2019-12-11 19:43:24
问题 I want to design a class in C++ called Entity. That entity has a pointer to a member of Vector3D which is the position of the entity in 3D space. The constructor allows a pointer of type Vector3D to be passed to the constructor, such that the Vector3D instance is instantiated outside of the class. Because there is a pointer to a dynamically allocated object, the copy constructor and assignment operator must be overloaded to deep copy the vector. However, because the vector can be passed in

Inheritance vs using a class object of one class as a field of another class (Python 3)

十年热恋 提交于 2019-12-11 18:17:41
问题 Say we have a product which is identifiable by an ID number and a Quality field which is in turn comprised of several values, one of which is 2d dimensions values. Is this a case of inheritance or just using an object as another classes' field ? In trying to implement the above in Python using OOP and classes I thought of the following: class Dimensions: def __init__(self, x, y): self.x = x self.y = y class Quality: def __init__(self, val1, val2, dimensions): self.val1 = val1 self.val2 = val2

Simulate inheritance using functional programming in React Redux application

久未见 提交于 2019-12-11 17:12:58
问题 I have a component, I want to be able to override the render method and certain methods in that component. In React you cannot use inheritance. There could be a way using composition in functional programming, but how would you actually go about composing the render and all the methods into separate components. For React default component functions such as componentDidUpdate , would you be able to composition it as a separate component that you bring in to a higher-order component (HoC). How

Aggregation or composition or simple association?

…衆ロ難τιáo~ 提交于 2019-12-11 14:39:32
问题 There is one example to explaining associations in UML. A person works for a company; a company has a number offices. But I am unable to understand the relationship between Person, Company, and Office classes. My understanding is: a company consists of many persons as employees but these classes exist independently so that is simple association with 0..* multiplicity on Person class' end a company has many offices and those offices will not exist if there is no company so that is composition

Composing expression trees for composite DTO

血红的双手。 提交于 2019-12-11 13:12:20
问题 Let's say I have the 3 followings DTOs public class Mailing { public long Id { get; set; } //... public long IdSender { get; set; } public Sender Sender { get; set; } public long IdTemplate { get; set; } public Template Template { get; set; } } public class Sender { public long Id { get; set; } public string Email { get; set; } //... } public class Template { public long Id { get; set; } public string Name { get; set; } //... } And I have 3 expression trees to manage DAO-to-DTO conversion :

How to delegate interface calls to a member that implements the interface

老子叫甜甜 提交于 2019-12-11 11:18:33
问题 Suppose, I have an interface ICry that has functions that return the sound of an animal: public interface ICry { string Cry(); } I have several classes that implement ICry: class Cat : ICry { public string Cry { get { return "Meow!"; } } } class Dog: ICry { public string Cry { get { return "Woof"; } } } If I have a PetOwner object that owns a pet, and I know this PetOwner can Cry(), but want to hide how he cries, I could do the following: class PetOwner : ICry { private Cat cat = new Cat();

React.js: Defining custom attributes

吃可爱长大的小学妹 提交于 2019-12-11 10:22:47
问题 React has a few custom defined attributes. How can I define my own? Why? I have an Arc component, a few usage examples below: <Arc startAngle="90" endAngle="270" stroke="hsl(38, 100%, 50%)" strokeWidth="0.5" /> <Arc startAngle="45" endAngle="90" fill="hsla(38, 100%, 50%, 0.2)" /> <Arc startAngle="0" endAngle="45" className="pie-slice" /> startAngle and endAngle attributes are required. All the other props are DOM properties that I just "proxy" to the root node. var Arc = React.createClass({

function composition with rest operator, reducer and mapper

瘦欲@ 提交于 2019-12-11 07:09:12
问题 I'm following an article about Transducers in JavaScript, and in particular I have defined the following functions const reducer = (acc, val) => acc.concat([val]); const reduceWith = (reducer, seed, iterable) => { let accumulation = seed; for (const value of iterable) { accumulation = reducer(accumulation, value); } return accumulation; } const map = fn => reducer => (acc, val) => reducer(acc, fn(val)); const sumOf = (acc, val) => acc + val; const power = (base, exponent) => Math.pow(base,