Search code examples
access-modifiers

what exactly does the word "client" means here?


i am reading a book and it says: "Two access modifiers you have looked at so far are public and private. If a method or property of the base class is exposed as public, it is accessible by both the derived class and any client of the derived class. If you expose the property or method of the base class as private, it is not accessible directly by the derived class or the client."

what does the 'client' means?


Solution

  • A client in this context means a piece of code outside the class (neither part of the class nor part of a derived class) which uses the class.

    That's it, really. Like the client of a bank or the client of an accounting firm, it's something that uses the thing you're discussing (be it bank, accounting firm or class).

    Public and private (and other variations) allow you to control how much of the internals of your class are exposed to the outside world. Minimising this exposure is known as encapsulation (information hiding) and is generally considered a good thing.