extend - Extending class in Java and constructing using an instance of the extended class -
I would like to expand a square and then copy that version of the value that has been extended, so I If it does not understand all its parameters in my new category, then what I'm trying to do is a simple example:
Public class MyTableModel default tellable model {public MyTableModel (public) DefaultTableModel model) {This = (MyTableModel) model; / * I know this is invalid * / / public newMethod () {// some extra code}}
Is it possible?
It looks like you composition inheritance Instead of wanting, in particular, it seems that you are trying to use. That is, you want to take a current example of DefaultTableModel
, and create another DefaultTableModel
which the underlying representative wants to take most of the methods forward, but maybe some Add / modify / decorate
you An example of this pattern is: A which calls all its methods in another collection. In order to modify the behavior of the backing collection to the subclasses, one or more ways should be overriden to do according to the decorator pattern. You can see to see how this pattern is generally implemented: As you can see, all this = somethingElse;
can never be set, but you can be DefaultTableModel rep
, and
by forwarding all the methods to its also see
Guava example:
ForwardingColution
@ Override protected summary archive & lt; E & gt; Representative(); Public full size () {return representative (). Shape (); } Public Boolean is empty () {Return Representative (). IsEmpty (); } Public Boolean removed all (collection & lt;? & Gt; collection) {return representative (). All deleted (archives); } // Too many interface collection methods have been implemented as above ...
forwarding compile
< Code> archive representative ()
, another archive
. Obviously this is not a duplication and world code to write, but now the subclass simply increases the forward quality
and only what they decorate to decorate.
Comments
Post a Comment