Polymorphism java declaration12/29/2023 Sometimes, you should just quit while you're behind :-) Perhaps I should have stated that a polyp was many occurrences of the letter p although, now that I've had to explain the joke, even that doesn't seem funny either. The monomer styrene happens to be made from carbon and hydrogen, C 8H 8, and polystyrene is made from groups of that, (C 8H 8) n. (a) I originally wrote that as a joke but it turned out to be correct and, therefore, not that funny. Learn it, understand it, love it - you'll be glad you did :-) There have been many "silver bullets" during my long career which basically just fizzled out but the OO paradigm has turned out to be a good one. Object orientation, polymorphism and inheritance are all closely-related concepts and they're vital to know. This is in contrast to the old way of doing things in which the code was separate from the data, and you would have had functions such as drawSquare() and drawCircle(). To get the correct behavior for any shape. In this example, every class would have its own Draw() function and the client code could simply do: shape.Draw() An irregular polygon needs a series of lines.īy making the class responsible for its code as well as its data, you can achieve polymorphism. A square or rectangle needs two co-ordinates for the top left and bottom right corners and (possibly) a rotation. A point shape needs only two co-ordinates (assuming it's in a two-dimensional space of course). With polymorphism, each of these classes will have different underlying data. The classic example is the Shape class and all the classes that can inherit from it (square, circle, dodecahedron, irregular polygon, splat and so on). They're rarely considered as objects in the usual term.īut, in that same way, a class like BigDecimal or Rational or Imaginary can also provide those operations, even though they operate on different data types. So polymorphism is the ability (in programming) to present the same interface for differing underlying forms (data types).įor example, in many languages, integers and floats are implicitly polymorphic since you can add, subtract, multiply and so on, irrespective of the fact that the types are different. Morph = change or form: morphology = study of biological form, Morpheus = the Greek god of dreams able to take any form. Poly = many: polygon = many-sided, polystyrene = many styrenes (a), polyglot = many languages, and so on.If you think about the Greek roots of the term, it should become obvious.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |