Andrei Botalov
Andrei Botalov

Reputation: 21096

Naming public static final in lowercase?

I have a hierarchy of classes:

class Page {
}
class ChildPage1 extends Page {
    private static final String URL;
}
class ChildPage2 extends Page {
    private final String url;
}

Some pages have static urls but other don't. I need some methods like load() in parent class Page that will use url of it's descendant. I thought about implementing it in these ways:

Is it worth to not follow naming conventions in this case?

Upvotes: 0

Views: 96

Answers (1)

phlogratos
phlogratos

Reputation: 13924

You can solve your problem by adding an abstract method getUrl() to Page that has to be implemented in ChildPage1 and ChildPage2.

class Page {
    protected abstract String getUrl();
}

class ChildPage1 extends Page {
    private static final String URL;

    protected String getUrl() {
        return URL;
    }
}

class ChildPage2 extends Page {
    private final String url;

    protected String getUrl() {
        return url;
    }
}

Upvotes: 1

Related Questions