====== [Java] Polymorphism ====== * description : [Java] Polymorphism * author : 오션 * email : shlim@repia.com * lastupdate : 2022-03-18 ===== [Java] Polymorphism ===== === 객체지향의 사실과 오해 역할, 책임, 협력 관점에서 본 객체지향 === == 조영호 (지은이) 위키북스 7쇄 발행 2022년 01월 27일 (1쇄 발행, 2015-06-17 ) == ● 책임을 수행하는 방법은 자율적으로 선택할 수 있다 요청을 받은 사람들은 요청을 처리하는 방법을 자유롭게 선택할 수 있다. 커피 제조를 요청받은 바리스타는 자신만의 독특한 방법으로 커피를 제조할 수 있다. 어떤 바리스타는 카푸치노의 거품을 이용해 커피 표면에 아름다운 무늬를 만들기도 하고 어떤 바리스타는 아메리카노의 향을 좀 더 향기롭게 만드는 방법을 알지도 모른다.__중요한 것은 커피를 제조하라는 동일한 요청을 받더라도 바리스타의 역할을 수행하는 사람들마다 서로 다른 방식으로 요청을 처리할 수 있다는 것이다.__ 이처럼 __동일한 요청에 대해 서로 다른 방식으로 응답할 수 있는 능력을 **''다형성(polymorphism)''**__이라고 한다. \\ \\ ==== Java Polymorphism ==== Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance. \\ * 다형성(Polymorphism)은 "많은 형태"를 의미하고, 상속(inheritance)으로 서로 연관된 많은 클래스들이 있을 때 다형성이 존재합니다. \\ Like we specified in the previous chapter; Inheritance lets us inherit attributes and methods from another class.\\ Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.\\ \\ * 이전 챕터에서 명시했던 것처럼, 상속(Inheritance)을 통해 다른 클래스의 속성(attributes)과 메소드(methods)를 상속받을 수 있습니다. * 다형성(Polymorphism)은 상속받은 메소드를 사용하여 다른 작업을 할 수 있습니다. 이를 통해 다양한 방식으로 단일 작업을 할 수 있습니다. \\ For example, think of a superclass called Animal that has a method called animalSound().\\ Subclasses of Animals could be Pigs, Cats, Dogs, Birds \\ And they also have their own implementation of an animal sound (the pig oinks, and the cat meows, etc.):\\ * 예를 들어, animalSound() 라는 메소드를 가지고 있는 Animal 슈퍼클래스를 생각해 봅시다. 동물의 하위 클래스들은 돼지, 고양이, 개, 새 등이 동물의 하위 클래스과 될 수 있습니다. - 그리고 동물의 하위 클래스들은 각 동물의 울음소리를 구현합니다. \\ \\ polymorphism, 폴리모피즘\\ → 다형성 (그리스어: 여러 개의 형태. poly(하나 이상), morph(형태)\\ \\ 다형성(多形性)\\ → 같은 종(種)의 생물이면서도 어떤 형태나 형질이 다양하게 나타나는 현상. 예를 들어 암수에 따라 크기, 형태, 색깔 따위가 차이나는 것이다.\\ 출처 : 네이버 사전\\ \\ \\ ==== Polymorphism ==== Polymorphism is the presentation of one interface for multiple data types.\\ * 다형성(Polymorphism)은 여러 유형의 데이터에 대한 하나의 인터페이스를 나타내는 것입니다. For example, integers, floats, and doubles are implicitly polymorphic:\\ regardless of their different types, they can all be added, subtracted, multiplied, and so on.\\ * 예를 들어, integers(정수형), floats(실수형, 7자리), doubles(실수형 15~16자리)는 내재적으로는 다형성을 가집니다: * 각자의 다른 데이터 유형과 관계없이 모두 더하기, 빼기, 곱하기 등이 가능합니다. In the case of OOP, by making the class responsible for its code as well as its own data,\\ polymorphism can be achieved in that each class has its own function that (once called) behaves properly for any object.\\ * OOP (Object-Oriented Programming, 객체 지향 프로그래밍)에서는, 클래스가 자체 데이터뿐만 아니라 자체 코드를 담당하게 만들어서 * 각각의 클래스가 (일단 호출되면) 모든 객체에 대해 정확히 동작하는 고유의 function을 가진다는 점에서 다형성을 달성할 수 있습니다. ==== Ref ==== [[https://developer.mozilla.org/en-US/docs/Glossary/Polymorphism|Polymorphism]]\\ [[https://www.w3schools.com/java/java_polymorphism.asp|Java Polymorphism]]\\ {{tag> 오션, polymorphism}}