简体   繁体   中英

Define a Wrapper for non-primitive types(classes)

I am implementing a middleware service provider in a distributed system, which provide lock management to the methods which are calling it,

we may have many commands requiring this service

Actually this service checks some conditions to see if it is safe to execute the command and if it is safe then it executes the command on a remote object,

I was thinking of defining a wrapper which receives the command , do the locking and return the result of command execution,

Is there any way to implement such a pattern ?

Thanks , Arian

As I understand you need to use Proxy pattern. Look in this answer for more details about how to do this in java. I think this is exactly what you need.

It's the Proxy pattern. The G4 book (Erich Gamma) cites an example which is just what you need: a Protection Proxy. This is essentially your proposed solution, create a new class which encapsulates the locking and access control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM