composition

Managing (and renaming) instance variables of class compositions

元气小坏坏 提交于 2019-12-11 03:55:52
问题 I would like to make a class composition so that the instance variables of the composing classes become instance variables of the composition but with adjusted names. The application for this is in defining new objects for drawing in matplotlib. One example is that I would like to have a function drawMyArrow that draws an arrow with possibly different colors (and other specifications) for its head, tail, and arc. I would like to be able to pass various specifications for the head, tail, and

Recursively (?) compose LINQ predicates into a single predicate

☆樱花仙子☆ 提交于 2019-12-11 02:58:09
问题 (EDIT: I have asked the wrong question. The real problem I'm having is over at Compose LINQ-to-SQL predicates into a single predicate - but this one got some good answers so I've left it up!) Given the following search text: "keyword1 keyword2 keyword3 ... keywordN" I want to end up with the following SQL: SELECT [columns] FROM Customer WHERE (Customer.Forenames LIKE '%keyword1%' OR Customer.Surname LIKE '%keyword1%') AND (Customer.Forenames LIKE '%keyword2%' OR Customer.Surname LIKE '

error: constructor Player in class Player cannot be applied to given types;

≡放荡痞女 提交于 2019-12-11 02:19:36
问题 whenever I compile my code, I receive the following errors: error: constructor Player in class Player cannot be applied to given types; but it doesn't list any types. The code in question is public class Team { private String name; public Player players[]; public Player temp; public Team(String inputname, Player players[]) { inputname = name; this.players = new Player [players.length]; for( int k=0 ; k<players.length ; k++ ) this.players[k] = new Player(players[k]); //This is the line with

Java composition (has-a) relationship clarification

為{幸葍}努か 提交于 2019-12-10 18:49:32
问题 I'm having trouble grasping the concept of composition. I need to create a manufacturer class and a products class and use composition. Do I make the has-a reference inside products and just add the manufacturer object when creating a new product? 回答1: That is exactly what is intended, and it makes sense. The manufacturer is a perfectly reasonable property of a product, and it seems reasonable to have a reference to the manufacturer in the object. About your list, you're not being asked to

Is there a way to reassign $this?

十年热恋 提交于 2019-12-10 17:29:48
问题 First of all, I do not want to extend a class. I would ideally like to do this. public function __construct() { /* Set Framework Variable */ global $Five; $this =& $Five; } I have a system where the variable $Five is a container class which contains other libraries. I could assign this to a local variable of Five... i.e. public function __construct() { /* Set Framework Variable */ global $Five; $this->Five = $Five; } However, the reason why I am trying to avoid this is that function calls

Java Swing: Does the phrase “favor composition over inheritance” apply?

回眸只為那壹抹淺笑 提交于 2019-12-10 16:52:29
问题 Does the phrase "favor composition over inheritance" apply to Swing components? I'd like to gather some professional opinions about the subject and which code is easier to maintain before I go ahead and design a UI. 回答1: Does the phrase "favor composition over inheritance" apply to Swing components? Yes. The only time I extend a Swing component is when I need to override one or more of the methods. For instance, I'll extend a JPanel when I want to override the paintComponent method. All other

Are 'currying' and 'composition' the same concept in Javascript?

假装没事ソ 提交于 2019-12-10 12:32:06
问题 Recently I read about function composition in a Javascript book, and then on a website I saw someone reference it as currying. Are they the same concept? 回答1: @Omarjmh's answer is good but the compose example is overwhelmingly complex for a learner, in my opinion Are they the same concept? No. First, currying is translating a function that takes multiple arguments into a sequence of functions, each accepting one argument. // not curried const add = (x,y) => x + y; add(2,3); // => 5 // curried

Accessors Composition in ES6 Classes

人走茶凉 提交于 2019-12-10 12:00:47
问题 Let's say I have a Thing class which I want to be both Hideable and Openable . Using a similar approach to Douglas Crockford's object creation through composition, I have been able to "inherit" from multiple classes. This approach does not work with accessors (getter/setters). I need to use classes as it's a requirement. I'm also finding that I am duplicating functionality from class to class, but I don't want these to inherit from a base class. Any ideas? The progress I have made so far is

Is it possible to parameterize a MEF import?

允我心安 提交于 2019-12-10 09:28:46
问题 I am relatively new to MEF so I don't fully understand the capabilities. I'm trying to achieve something similar to Unity's InjectionMember. Let's say I have a class that imports MEF parts. For the sake of simplicity, let's take the following class as an example of the exported part. [Export] [PartCreationPolicy(CreationPolicy.NonShared)] public class Logger { public string Category { get; set; } public void Write(string text) { } } public class MyViewModel { [Import] public Logger Log { get;

Compositing two images with python wand

一个人想着一个人 提交于 2019-12-10 04:10:15
问题 I need to use python wand (image-magick bindings for python) to create a composite image, but I'm having some trouble figuring out how to do anything other than simply copy pasting the foreground image into the background image. What I want is, given I have two images like: and both jpegs, I want to remove the white background of the cat and then paste it on the room. Answers for other python image modules, like PIL, are also fine, I just need something to automatize the composition process.