Sometimes mutators are useful. But they can be tricky to think about. For
example, what does this sequence of statements make? First, we create a
variable box of type Rectangle, and put a Rectangle in it. Then, we create
another variable of the same type, but I want it to be the same. So, I'm just
going to use box. Now, I actually realize I need to get the original box out of
the way. So, I'm just going to translate it. So, this would look something
like, we would create a rectangle. And then, we create another rectangle that's
the same. Then, we translate it out of the way. What is the value of box.getX?
What is the value of box2.getX?
A veces los mutadores son útiles. Pero pueden ser difíciles de entender. Por
ejemplo, ¿qué imprime esta secuencia de declaraciones? En primer lugar, creamos un
variable box (caja) de tipo Rectángulo y ponemos un rectángulo en el mismo. Luego creamos
otra variable del mismo tipo, pero quiero que sea la misma. Así que sólo
voy a usar box. Ahora, me doy cuenta de que realmente quiero quitar el box original
de en medio. Así que sólo voy a trasladarlo. Por lo tanto, esto se vería como algo
así, crearíamos un rectángulo. Y luego creamos otro rectángulo que es
igual. Entonces, lo trasladamos fuera del camino. ¿Cuál es el valor de box.getX (caja.obtenerX)?
¿Cuál es el valor de box2.getX?
Parfois, les mutateurs sont utiles.
Mais ils peuvent être épineux.
Par exemple, que fait cette
séquence d'instructions?
D'abord, nous créons une variable box
du type rectangle et y mettons un rectangle.
Ensuite, nous créons
une autre variable du même type,
mais je veux que ce soit la même chose.
Donc, je vais utiliser box.
Maintenant, je réalise que je veux
enlever le premier box.
Donc, je vais la traduire.
Cela ressemblerait à quelque chose comme,
nous créerions un rectangle
et nous en créons un autre
qui est le même.
Ensuite, nous le traduisons à l'écart.
Quelle est la valeur de box.getX?
Quelle est la valeur de box2.getX?
ミューテータは便利ですが
考えるのが厄介でもあります
次の命令文でどうなるか見てみましょう
まず変数boxを作成し型はRectangleにします
Rectangleをその中に入れます
同じ型の変数をもう1つ作りますが
上の変数と同じにしたいので
boxを使います
元のboxは片づけなくてはいけません
そこでこれを変換すると長方形が作れそうです
さらに同じ長方形をもう1つ作ります
それを変換して片づけます
box.getXの値は何でしょう
またbox2.getXの値は何でしょう
어떨 때 변환자는 유용합니다. 하지만 변환자는 이해하기 어려울 수도 있습니다.
예를 들어서, 이 연속적인 진술들은 무엇을 만들어내나요? 첫 번째로,
변수명은 box, 자료 형은 Rectangle이라는 변수를 만들고 안에 Rectangle 객체를 저장힙니다. 그런 후에 우리는
같은 자료형의 변수를 만듭니다. 하지만 저는 똑같게 선언하길 원합니다. 그래서 저는
box를 저장하겠습니다. 이렇게 하면 box와 box2는 겹친다는 것을 알았습니다.
그래서 box를 옮기겠습니다. 지금 상황을 보면,
직사각형 하나를 만들고, 또 같은 직사각형을 만들게 됩니다.
그런 후에, 우리는 하나의 위치를 옮길겁니다. box.getX의 값은 무엇인가요?
box2.getX의 값은 무엇인가요?
Soms zijn mutators nuttig.
Maar ze kunnen netelig zijn.
Wat print deze reeks instructies?
Eerst maken we een variabele box
van het type rechthoek en
plaatsen er een rechthoek in.
Dan maken we een andere
variabele van hetzelfde type,
maar ik wil dat deze hetzelfde is.
Dus ik ga gewoon
box gebruiken.
Nu besef ik dat ik de originele box
uit de weg wil ruimen.
Dus ik ga het gewoon vertalen.
Dus dit zou er ongeveer zo uitzien,
we zouden een rechthoek maken.
Dan maken we een andere
rechthoek die dezelfde is
en we vertalen het uit de weg.
Wat is de waarde van box.getX?
Wat is de waarde van box2.getX?
Đôi khi hàm gán rất hữu dụng, Nhưng nó có thể khó vận dụng.
Ví dụ, những dòng này sẽ làm công việc gì?. Trước tiên, chúng ta tạo một
đối tượng "box" kiểu Rectangle, và truyền vào giá trị. Sau đó, chúng ta tạo
một đối tượng khác cùng loại nhưng tôi muốn nó tương tự. Vì vậy, tôi chỉ cần
dùng đối tượng "box". Bây giờ tôi mới nhận ra rằng tôi cần một đối tượng box gốc
Thế nên, tôi sẽ làm thay đổi nó. Và đây nó sẽ trông như vầy
chúng ta sẽ tạo một đối tượng mới từ Rectangle. Rồi sau đó tạo một đối tượng khác cũng từ Rectangle nhưng
tương tự đối tượng kia, rồi thay đổi nó. Bây giờ giá trị của box.getX sẽ là gì?
và box2.getX sẽ là gì?