سؤال

I've got a class, like this, simplified:

public class Bookmark
{
    public string Nav     { get; set; }
    public string Scroll  { get; set; }
    public string Comment { get; set; }

    public string guid()
    {
        return guid_static(this.Nav, this.Scroll);
    }

    public static string guid_static(string nav, string scroll)
    {
        // some complex equations on nav & scroll
        return result;
    }
    ...
}

From outside the class, I need to launch both (instance and static) methods. First - to get a guid for the existing bookmark. Second - to generate a guid for the certain "position" (nav & scroll values) which is not a bookmark (though has not an instance) to compare with another guid.

Are these 2 methods OK, in terms of the OOP concepts? Or I must introduce a new class like "Position" with the only guid() method? Isn't there an "official" object-oriented workaround? (I just don't want to multiply classes quantity)

P.S. If it's OK, what is the naming conventions for twinned static and instance methods?

هل كانت مفيدة؟

المحلول

You can actually name them both "guid" if you want to. Most languages will automatically know the difference between you calling guid() versus guid(nav, scroll) because the method signatures are different. The way you have it coded currently is otherwise fine.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top