composition

Is it always a bad idea to extend JFrame?

你说的曾经没有我的故事 提交于 2019-12-07 13:56:03
问题 When developing Java Swing GUIs, is it always a bad idea to extend JFrame? And what about JPanel, or other JComponents? Also, what makes it bad? 回答1: Usually it's a rule of thumb to only subclass if you need to customize the Swing component. 来源: https://stackoverflow.com/questions/9742018/is-it-always-a-bad-idea-to-extend-jframe

java inheritance versus composition (implementing a stack)

落爺英雄遲暮 提交于 2019-12-07 11:56:50
问题 I am trying to implement a Stack in java (using the list interface: Interface List). I want to implement it two different ways: using composition and inheritance. For inheritance, so far I have: import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; public class StackInheritance implements List { //implement list methods } For composition, I have: import java.util.List; public abstract class StackComposition implements List { // implement

Whether to model a car object (and its parts such as engine) with has-a (composition) or is-a (inheritance)?

北战南征 提交于 2019-12-07 08:28:42
问题 I am developing a class library which will include the object Car. The dilemma is, Car itself will be a class with fields such as Registration Number, and other general information on the car. But a car has an engine, chassis, etc. These objects need to be modelled too. Should they be classes embedded within Car? If not, what is the usage scenario of an embedded class? I've learnt that composition is "part of", so you can model seperate classes and use the engine type, for example, at the

Javascript Distinguish between Composition vs. Inheritance

。_饼干妹妹 提交于 2019-12-07 06:35:26
in the classfull-Style (c++) or in the traditional Design Patterns (GofPatterns) it is really clear, what is the difference between composition and inheritance and how it is implemented and when to use what (advantages/disadvantages). But how do you distingish between Composition or the "normal" Inheritance in JS? or it is used as the same term? Is a prototype inheritance for example defined as a composition or inheritance? What are you guys thinking? Peter Seliger Is a prototype inheritance for example defined as a composition or inheritance? What are you guys thinking? It is not about what I

Avoid temporary variables by using name shadowing

房东的猫 提交于 2019-12-07 04:53:11
问题 I create a lot of temporary variables in Haskell: main = do let nums'' = [1..10] let nums' = a . bunch . of_ . functions $ nums'' let nums = another . bunch . of_ . functions $ nums' print nums That is, I don't want to write a long chain of functions like so: let nums = another . bunch . of_ . functions . a . bunch . of_ . functions $ [1..10] Because it becomes unreadable to me, so I try to group the functions according to what they do. In the process I end up creating a bunch of ugly

How to overload an operator for composition of functionals in C++0x?

让人想犯罪 __ 提交于 2019-12-07 04:00:51
问题 Is there a way to overload, say the >> operator for function composition? The operator should work seamlessly on lambdas as well as std::function ? Requirements: The solution should not include nested bind calls, the left operand can be of a functional type with an arbitrary number of parameters, and no more than one function object instance should be created. Here is a quick and dirty example that illustrates the desired behaviour: #include <iostream> #include <functional> using namespace

WPF Composition/Agregation

£可爱£侵袭症+ 提交于 2019-12-06 16:59:34
I'm looking for documentation regarding WPF best practice for Compositing and agregating the user interface in a large project. I'm comming from a visual Inheriance world using Delphi and Winform. And I'm now try to replicate that kind of pattern well in fact reusability of those UI elements. I'm open to suggestion and reading. The Composite Application Guidance (sometimes called "Prism") is appropriate, especially if the application has a lot of moving parts developed by different teams. We've been using this for a while and while the patterns aren't very similar to what you've experienced

Haskell (.) for function with multiple operands

瘦欲@ 提交于 2019-12-06 01:59:33
问题 The (.) operator has the signature: (.) :: (b -> c) -> (a -> b) -> a -> c (.) f g x = f $ g x This looks a bit similar to the composition function in primitive recursive functions with one g . I'm not interested in extending the number of g -functions, but (a number of) functions that apply the (.) function on a function g with multiple operands. In other words something like: (..) :: (c -> d) -> (a -> b -> c) -> a -> b -> d (..) f g x y = f $ g x y A search on Hoogle doesn't result in any

Rails 3 with composed_of model and validation

ぃ、小莉子 提交于 2019-12-05 23:08:22
I have this domain model: class Person < ActiveRecord::Base composed_of :address, mapping: [%w(address_street street), %w(address_city city), %w(address_zip_code zip_code), %w(address_country country)] validates :name, presence: true, length: { maximum: 50 } validates :surname, presence: true, length: { maximum: 50 } validates_associated :address end class Address include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming attr_reader :street, :city, :zip_code, :country validates :street, presence: true validates :city, presence: true validates :zip_code,