据我了解,当我持有对另一种类型的引用作为代理类中的成员时,我实现了代理模式。我还需要提供一个与主题类型相同的接口,并控制对真实对象的访问。
所以,如果我的代码看起来像这样,当 List 成员是主题类型时,我会正确实现代理模式吗?
public class ListUsers
{
public List<User> UserList { get; set; }
.
.
// Ctor and other methods that dont expose the "List<Users>" properties..
.
.
public void Add(User i_User)
{
// added logic and control.
if (!this.UserList.Exists(x => x.Id == i_User.Id))
{
this.UserList.Add(i_User);
this.SetUserPassword();
}
else
{
.
.
.
}
}
}
另外,如果我的描述是正确的,那会使任何具有任何类型成员的类成为代理模式类吗?