composition

Guidance in creating design for multiple-inheritance composite classes in c++

纵饮孤独 提交于 2019-12-13 06:02:58
问题 I intend this question to be a more generalized question relating to my question found at the following link: Solving design involving multiple inheritance and composite classes in c++ I am working with data sets related to Galaxies. The data about each galaxy will contain information about a galaxie's solar systems, each solar systems planets and each planets moons. The Composite Requirement: From this alone I imagine that I need to use composite class design where I create a class for the

guidance with OO design of my UML diagram

喜欢而已 提交于 2019-12-13 05:13:31
问题 Could I please get some feedback on this UML diagram? It's a simplified diagram only showing the layout and interconnectivity of the classes with instance variables, constructors and methods intentionally left out at this point in time. Inventory Project Simplified UML Diagram The main thing I need guidance with is the object-oriented design. Do I have the right classes implementing interfaces or should I move the interface(s) to subclass(es)/superclass(es), do I have the association,

Modify render function of external React component (with no access)

假如想象 提交于 2019-12-13 04:39:45
问题 I have to use a react component that I cannot modify. It's from an external source, due to changes. This could also be a component from a npm package that I import. This is what it looks like, a simple button: class Button extends React.Component { // ... more code above render() { const { onClick, disabled, children} = this.props; return ( <button className={this.getClasses()} onClick={onClick} disabled={disabled}> {this.props.symbol && <Icon symbol={this.props.symbol} />} {children} <

How to nest endpoints in a API client with interfaces while keeping readability

我怕爱的太早我们不能终老 提交于 2019-12-13 02:54:41
问题 I'm trying to compose a simple API client I'm stuck trying to figure out how to make it readable and testable. How can I compose a nested structure while keeping it testable? Psuedo code: type VehicleEndpoint struct { Car CarEndpoint VehicleGetter } type VehicleGetter interface { Get(string) Vehicle } type Vehicle struct { kind string } type VehicleClient struct { http.Client url string } func (v *VehicleClient) Get(kind string) Vehicle { resp := v.Do(v.url, kind) return Vehicle{ kind: resp

How do I organize data by common traits?

不想你离开。 提交于 2019-12-12 12:34:45
问题 I'm having trouble cataloging data in a way that allows me to reference data by its common descriptors or traits. I'm well aware of inheritance, traits (the programming concept), and interfaces, but none of those seems to be the right answer to my problem. I'm writing a program in JavaScript that has potentially many different items or objects. Let's say I have a datatype of WoodenShortSword and I want to express that it has the traits of being Flammable and Weapon and OneHanded . Then, I

Composition: using traits to avoid forwarding functions?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 10:32:31
问题 Let's say we have two classes, A and B . When using composition to model a "has-a" or "is-implemented-in-terms-of" relationship (e.g. B has-a A ), one of the drawbacks vs. inheritance is that B does not the contain public functionality of A that it requires. In order to gain access to A s public functions, it is necessary to provide forwarding functions (as opposed to inheritance, where B would inherit all of A s public functions). To give a more concrete example, let's say we have a Person

Composition/Inheritance/Factory - Best Pattern For This Case

◇◆丶佛笑我妖孽 提交于 2019-12-12 09:05:54
问题 Good [your_time_of_day], Today I have been learning about composition and factory functions in javascript (es6). I understand that composition should be preferred over inheritance and have come to agree with that (at least in javascript). Then, I realised that I have a situation where I should be using composition... Question first: Is there a way I can change my complex, inherited structure so classes are composed of functions without having ridiculous numbers of decorators? Have I missed

Composition, I don't quite get this?

点点圈 提交于 2019-12-12 03:12:16
问题 Referring to the below link: http://www.javaworld.com/javaworld/jw-11-1998/jw-11-techniques.html?page=2 The composition approach to code reuse provides stronger encapsulation than inheritance, because a change to a back-end class needn't break any code that relies only on the front-end class. For example, changing the return type of Fruit's peel() method from the previous example doesn't force a change in Apple's interface and therefore needn't break Example2's code. Surely if you change the

C++ access private member in composition of two classes from base class

你说的曾经没有我的故事 提交于 2019-12-12 02:58:30
问题 Since I'm a newbie in C++, here it goes! I have a base class (I'm not using inheritance anywhere) with two objects from two other classes. I need to have access from a private member to the other in another class. class base { private: myClass1 m1; myClass2 m2; public: base() {}; ~base() {}; }; class myClass1 { private: int m_member1; public: myClass1() {}; ~myClass1() {}; }; class myClass2 { private: int m_member2; public: myClass2() {}; ~myClass2() {}; int sum_members_because_yes(void) {

Click event delayed in ContextMenu attached to NotifyIcon

你离开我真会死。 提交于 2019-12-12 02:27:27
问题 I am working on a plugin (using System.ComponentModel.Composition ) for an application to place an icon in the notification area of the Windows UI. trayMenu.MenuItems.Clear(); // Create context menu items foreach( IJob job in jobs ) { MenuItem menuItem = new MenuItem( job.Name ) {Tag = job}; menuItem.Click += MenuItemClick; trayMenu.MenuItems.Add( menuItem ); } private void MenuItemClick( object sender, EventArgs e ) { // ... } Now when I click on an item in the context menu of that icon, the