• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hairy about generics (Challenge)

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I was trying to create a code example for a (as I imagine) useful pattern I would like to call "friend pattern". The name of the pattern is inspired by the C++ "friend" keyword.

Imagine you have a bunch of classes that stores some data, each with different properties and you would like to create a editor (friend) for each of these classes. Of course, these classes has no business of knowing how they can be edited and we would like to define separate classes to edit them. The pattern I called "friend" pattern provides a way other programmers to add their own data classes and editors without having to rebuild any existing component.

I tried to use generics in my example code as much as possible but when I write the last two line I realized I am stuck. I didn't think this through and the last two line won't compile. I realized I might have to change quite a bit of code and remove some of the generics usage. I would really hate that because I find java's generic very self-documenting and make my idea easy to read and understand.

Can someone help me to make minimum number of changes and make the code compile?





thanks
 
Peter Hsu
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh by the way...
I just wanted to say I know why this code wouldn't compile, but I realize if I want to make the code compile I would have to remove a while bunch of generics and I want to minimize that
 
Peter Hsu
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
found solution

line 40~43:




line 82~92

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic