parameterized wrapper class with a superclass

(This looks like a low-level and widely usable implementation pattern. If it is, then we better learn to read it. However, I don’t see many java guys create generic classes.)

 

A wrapper class’s behavior is affected by 3 types of things

 

·         The “kernel” fields wrapped in the wrapper. In addition, there are often helper fields, too.

·         The parent class

·         The type param. Remember this class is parameterized.

 

This looks simple until you see it used in a complex system. You need to remember how these “influences” are set.

 

public class EntityCacheListenerAdapter<K, V extends Entity, T extends EntityListener>

extends AbstractCacheListenerAdapter {

      public EntityCacheListenerAdapter(T target) {

            super(target); // populating this.target

      }

      @Override

      public void afterUpdate(EntryEvent event) {

            super.getTarget() // inherited from parent

             .entityUpdated( // this method is from the kernel field

                    event.getOldValue(), event.getNewValue());

      }

 

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

您正在使用您的 WordPress.com 账号评论。 登出 /  更改 )

Google photo

您正在使用您的 Google 账号评论。 登出 /  更改 )

Twitter picture

您正在使用您的 Twitter 账号评论。 登出 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 登出 /  更改 )

Connecting to %s