Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 23928
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.
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic