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
Post a Comment