Forum Stats

  • 3,855,526 Users
  • 2,264,517 Discussions
  • 7,906,040 Comments

Discussions

Accessor vs Mutator methods

843789
843789 Member Posts: 46,655 Green Ribbon
Nowadays I'm studying for SCJP 5.0 and I found a strange definition about Encapsulation .

When I have seen the "Accessor methods"

To me, it would be related with the both "setters" and "getters" methods

But on a mock I found this definition:

"Accessor methods are used to read data members; mutator methods are used to set data members. The mutator methods can validate the parameter values before the values are used to change the state of the internal data model."

on the mock this sentence would be strong:

"Accessors methods are used to prevent fields from being set with invalid data."

the correct would be:

"Mutator methods are used to prevent fields from being set with invalid data."

In order to do the exam, how the Sun call that methods?

- setters and getter methods?
- Accessor methods and Mutator methods?
- or only Accessor methods for the both?

Message was edited by:
oalexandrino

Comments

  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    > In order to do the exam, how the Sun call that methods?

    I don't think you'll see anything of the sort on the exam, based on the exam objectives.

    Aside from that, accessors are often referred to as "getters", while mutators are often referred to as "setters".

    ~
  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    edited Dec 1, 2006 2:07PM
    I asked that question because I found the following one on the example of mock:


    A class can not be called "tightly encapsulated" unless which of the following is true?

    a. All member fields are declared final.
    b. The class is not anonymous.
    c. The internal data model can be read and modified only through accessor and mutator methods.
    d. The class is an inner class.
    e. None of the above


    I think it would be found in:

    Section 5: OO Concepts



    all right?
  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    > all right?

    Sure. So do you have the information you need?

    ~
  • 843789
    843789 Member Posts: 46,655 Green Ribbon
    yes, I do!

    I understood!

    thank you!
This discussion has been closed.