A very simple question, but after reading Design Designs: Elements of reusable OO Software, I'm a little confused.
The book states
"The type of an object refers only to its interface - a set of requests to which it can respond. An object can have many types and objects of different classes can have the same type."
Can someone better explain what a Type is? I also do not understand how one object can have several types ... if the book does not talk about polymorphism ....
Maybe an example helps clarify. Suppose a class is a special type of type.
class Dog : Animal {...}; class Fish : Animal {...}; Dog lassie = new Dog(); // An object can have many types: // lassie is a dog and an Animal Fish nemo = new Fish(); // objects of different classes can have the same type: // lassie and nemo are animals
.
, . .
, Java ( ), ( /).
, .
"" ( ) - , square, rectangle, circle .. "", setPosition(), setSize() drawShape().
square
rectangle
circle
setPosition()
setSize()
drawShape()
. , , .
, , (). , . , , , .
IEntity, IMammal ISwimmer , , IEntity ISwimmer. - , , , , .
,
Source: https://habr.com/ru/post/1782399/More articles:Windows Azure POST Access Data - postjQuery to hide and show divs with indicator - jqueryThe average values of the Over the fold window - htmlHow to check that only one value in an array is nonzero? - ruby | fooobar.comКак использовать селектор ID после jQuery html() - javascriptВычисление с разным шагом для меток оси Y в Gnuplot - gnuplotUISplitViewController stops auto-rotation after trying to use UINavigationController inside it - iosHow to determine if a Bluetooth device is connected - androidHow to get Touch Event Pressure? - androidFile Ensime Vim.ensime Not Found - vimAll Articles