Software Access Modifiers Flashcards

1
Q

What are the two access modifier levels?

A
  • Top level (class level) – can use public
    • Member level (inside class) – can use public, private, protected
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do access levels affect programming?

A
  1. When using classes that come from another source, access levels determine which members of those classes your own classes can use.
  2. When writing a class, you need to decide what access level every member variable and every method in you class should have.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use access modifiers?

A

By making class members private or public, the class interface is clearly separated from the internal implementation of the class. This is called encapsulation. From a security viewpoint, encapsulation stops class members from being changed in an uncontrolled way (e.g. without proper validation, without notifying error handlers, etc).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to choose access modifiers?

A

Use the most restrictive access level that makes sense for a particular class member. Use private unless you have a good reason not to. Avoid public fields except for constants which cannot be changed.

Public fields tend to:
- Restrict the code to a particular implementation.
- Limit flexibility in changing the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are immutable objects?

A

An immutable object is an object whose internal state remains constant after it has been created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly