Your interpretation is correct--however I argue that the
"Substitutability Principle" would remain intact because both the
public accessor and public specifier would be inherited via their
public declarations.
Huh? You previously wrote you didn't want the property to be inherited.
Now you're saying that it would be? How does that work?
You seem to be confusing access modifiers (which only affect what code is
allowed to see members of a class) with inheritance (which isn't affected
by access modifiers).
Even private members are inherited. They can't be seen by inheriting
classes, but they still exist and they are visible to the declaring class,
even when the code in that declaring class is executing on an instance of
an inherited class. You can't stop base class members from being
inherited; it's a basic violation of OOP rules.
In essence, I am looking for the property form
of:
class Animal { private String name;
public String getName() { ... }
public void setName(String newName) { ... }
}
class Giraffe : Animal
{
}
There's no property in that example. There's a field, that's private.
And there's two public methods that (apparently) allow you to get and set
the field.
In your example above would not "g.Name" compile because (even though
the property was private) the compiler generated "getName()" would in
fact be public?
You most certainly could not write "g.Name" using your example and have it
successfully compile. A property is more than just a couple of
specially-named methods. Writing "getName()" and "setName()" methods does
not allow you to then use "Name" by itself as a property.
In any case, in what way is your example functionally different from:
class Animal
{
private String name;
public String Name
{
get { return name; }
set { name = value; }
}
}
In the above, a very conventional property declaration, the field where
the data is stored is still private, but the property and both accessors
are themselves public. How is that different from what you want to do?
What are you really trying to do here?
Pete