• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Using generics for a template pattern

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to create a template design pattern, starting with an abstract base class containing generic types, and an application class incorporating concrete types. It doesn't compile and I can't understand why.

The generic class is:



and the component class is:



But, the compiler doesn't like it:



What really throws me is the "found: no arguments". Anyway I am missing something conceptually here. Why this ExtensionClass is not a valid implementation of the GenericClass?
 
author
Posts: 23945
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric C Barnhill wrote:
What really throws me is the "found: no arguments". Anyway I am missing something conceptually here. Why this ExtensionClass is not a valid implementation of the GenericClass?



First, you are trying to use the GenericClass in its raw form. This should be done for backwards compatibility only. Second, your GenericClass class doesn't have a no-args constructor. A default no args constructor is only provided if no constructor is defined. And third, what is the purpose of having those instance variables in the GenericClass class, if they won't be used?

Isn't something like this better?



And also... you may want to make the GenericClass instance variables protected, or provide getters (also protected), so that the ComponentClass can access the values.

Henry
 
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That clarifies matters a great deal, thank you.
 
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic