Here we have the red ball in the ball class. One has to do two things. First of
all, the ball must implement the drawable interface. And we need to supply a
draw method, in this case the method was very simple. It simply fills the
circular shape. In the Scene class, we add a Ball, and that's it, nothing else
needs to be changed. The mechanism that does the drawing stays completely the
same. That's polymorphism in action. we have a general mechanism that can deal
with any drawables. And if we want to add more, then we can simply add them
without having to make any further changes.
Aquí tenemos la pelota roja en la clase Pelota. Uno tiene que hacer dos cosas. Ante
todo, la pelota debe implementar la interfaz Dibujable. Y tenemos que suministrar un
método draw, en este caso el método era muy simple. Simplemente llena la
forma circular. En la clase Escena, añadimos una pelota y eso es todo, no hay que
cambiar nada más. El mecanismo que hace el dibujo queda por completo sin
cambios. Eso es polimorfismo en acción. tenemos un mecanismo general que puede lidiar
con cualquier dibujable. Y si queremos añadir más, entonces podemos simplemente añadirlas
sin tener que hacer más cambios.
Ici, nous avons la balle rouge
dans la classe Ball.
Elle doit faire deux choses.
Tout d'abord, la balle doit implémenter
l'interface Drawable
et nous devons fournir
une méthode Draw,
dans ce cas la méthode était très simple.
Elle remplit simplement
la forme circulaire.
Dans la classe Scene,
nous ajoutons une balle.
Et c'est tout, rien d'autre
n'a besoin d'être changé.
Le mécanisme qui fait le dessin
reste complètement le même.
C'est le polymorphisme à l’œuvre.
Nous avons un mécanisme général
qui peut traiter tous les Drawables.
Et si nous voulons en
ajouter d'autres,
nous pouvons simplement les ajouter sans
avoir à apporter d'autres changements.
これは赤いボールです
Ballクラスでは必要なことが2つあります
まずDrawableインターフェースを実装し
そしてdrawメソッドを提供することです
この場合のメソッドは簡単です
ここに円形を意味する言葉を入れます
そしてSceneクラスでBallを追加します
他は何も変える必要はありません
描写のメカニズムは完全に同じです
それがポリモーフィズムの機能です
これによりどんなDrawableも処理できます
追加したい場合は単純に追加すればよいのです
他に変更することはありません
Ball 클래스 안에 빨간 공이 있습니다. 두 가지 일을 해야 합니다.
첫 번째로, Ball은 Drawable 인터페이스를 선언해야 합니다. 그리고 우리는
draw 메소드를 공급해줘야 합니다. 이 경우에는 메소드가 굉장히 간단했습니다.
동그란 모양을 채워줍니다. Scene 클래스에서 Ball을 추가하면 끝입니다.
출력을 하는 시스템은 변함없이 똑같습니다.
다형 변수가 잘 작동하고 있다는 것을 볼 수 있습니다. Drawable을 쉽게
추가할 수 있는 체계가 있고 더 많은 것을 추가하면, 다른 변화 없이
간단하게 추가할 수 있습니다.
Ta đã có một quả bóng đỏ trong Ball class. Ta phải làm 2 thứ.
Trước hết, Ball class phải implements Drawable interface. Và ta cần phải cung cấp draw method,
trong trường hợp này, method đó rất đơn giản. Chỉ là tô màu vào hình tròn.
Trong Scence class, ta thêm một quả Bóng, và xong rồi, không có gì khác
cần phải thay đổi. Kỹ thuật để làm việc drawing thì vẫn như cũ.
Đó là "polymorphism in action". (đa hình trong thực tế). Ta có một cơ chế chung,
có thể xử lý bất kỳ drawable nào. Nếu bạn muốn nhiều hơn, ta đơn giản chỉ là thêm nữa vào,
mà không phải sửa gì khác.