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 this = somethingElse; can never be set, but you can be DefaultTableModel rep , and

also see
  • Effective Java version 2, item 16: Follow the structure on heritage / em>

    Guava example: ForwardingColution

    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:

      @ 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 ...  

    As you can see, all forwarding compile < Code> archive by forwarding all the methods to its 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

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -