Tag Info

New answers tagged

1

You say "The only case I think you have to use getters and setters is if you need to do some operation besides the set or the get. ". You should use getters and setters if at some point in the future you might need to do some operation besides the set and get and you don't want to change thousands of lines of source code when that happens. You should use ...


0

The most important reason for limiting public access is to reduce the coupling in your application. By only exposing a select set of public methods or properties, you limit the number of connections between different classes. There is widespread confusion about this, where many people believe that the purpose of private access modifier is to prevent other ...


0

The tutorial appears to be demonstrating what you can do, not giving examples of what you should do. Specifically in this case, their use of properties means b.MyProperty below doesn't equal "Bob", which would fail code review in any shop I've worked in. HappyBirthday a = new HappyBirthday(); a.MyProperty = "Bob"; a.MyProperty = a.MyProperty; ...


3

The tutorial is trying to teach you about encapsulation. Encapsulation is an important part of Object Oriented Programming. It's a technique programmers use to keep their large codebases clean and easy to work with. Essentially, it means that anything that can be left as a private implementation of a class should be left private. This reduces the "public ...


6

The author provided a simple example which, due to its simplicity might make it more difficult for one to understand the importance of private methods. Private methods are a way in which you can encapsulate and break down the behavior of a given object without exposing them to the outside. Let us say that we have an object of type Person: public class ...



Top 50 recent answers are included