I am giving an example to better understand :-
Interface which contains profile name strings
public interface IProfile
{
string FirstName {get;}
string LastName {get;}
}
Implements IloggedUser interface.
public interface ILoggedUser
{
IProfile Profile
{
get;
set;
}
}
Class LoggedUser which implements ILoggedUser interface.
public class LoggedUser : ILoggedUser
{
protected IProfile _profile = null;
Constructor
public LoggedUser(IProfile Profile)
{
_profile=Profile;
}
public static LoggedUser Create(IProfile Profile)
{
LoggedUser User = new LoggedUser(Profile);
return User;
}
public IProfile Profile
{
get
{
if (_profile== null)
{
return _profile;
}
}
set
{
_profile=value;
}
}
}
Class profile which implements IProfile interface.
public class Profile : IProfile
{
string _firstName = string.Empty;
string _lastName = string.Empty;
public string FirstName
{
get
{
return _firstName;
}
}
public string LastName
{
get
{
return _lastName;
}
}
}
0 comments:
Post a Comment