c# - how is Proxy pattern defined? -


from understanding implement proxy pattern when hold reference type member in proxy class. need provides interface, identical subject type, , controls access real object.

so, if code this, when list member subject type, have been implementing proxy pattern correctly?

public class listusers {     public list<user> userlist { get; set; }      .     .     // ctor , other methods dont expose "list<users>" properties..     .     .      public void add(user i_user)     {         // added logic , control.         if (!this.userlist.exists(x => x.id == i_user.id))         {             this.userlist.add(i_user);             this.setuserpassword();         }         else         {             .             .             .         }     } } 

also, if description correct, make class has kind of member proxy pattern class??

no, not valid implementation of proxy pattern, because crucial feature of pattern implementation missing: proxy of object needs pretend it's thing proxying, either providing same interface, or providing implicit conversions proxied object.

if listusers implemented ilist<user> interface, proxy list<user>. similarly, if listusers let obtain special subclass of user lets read data not write it, special class proxy user.

.net uses proxy pattern in several notable places, such managing list access through list<t>.asreadonly, or synchronized wrappers of hashtable , arraylist.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -