开发者

What's the best solution to implement this?

I'm working with project that will have ONLY one profile that has friends

I allready do that by

  • static class profile

  • class friend

  • profile has static collection of friends

but profile and friend have same variables as name , pic , .. etc

so i decide to make a pers开发者_如何学编程on abstract class and inherit it

then i found that i can't inherit static class [ profile ] from person as variables will not have properties

so i made variables as static in person

then every friend doesn't have its variables as static variables will belongs to friend class

I'm new to this and i know it's a silly question !!

but what's the best way to implement this

I Preferred Using Static For Profile For Accessibility

I Preferred Using Static Things For Accessibility Purposes


Avoid using static classes. If you want one instance, just create one instance. Static classes make testing difficult.

But going back to design, maybe try introducing a User class:

class User
 - name
 - picture
 - other properties

class Profile
 - User myAccountInfo
 - List<User> friends


Maybe something like this?:

class User
{
    public User(string name, object picture)
    {
        Name = name;
        Picture = picture;
    }

    public string Name { get; set; }
    public object Picture { get; set; } //Change object to a class that holds Picture information.
}

class Profile : User
{
    private static Profile _profile;

    public List<User> Friends = new List<User>(); //This List<T> can contain instances of (classes that derive from) User.

    public Profile(string name, object picture) : base(name, picture) { }
    public static Profile GetProfile()
    {
        return _profile ?? (_profile = new Profile("NameOfProfileHere", null));
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜