본문 바로가기

Python Object-oriented Programming49

overriding-method 출처 :https://www.pythontutorial.net/python-oop/python-overriding-method/ Python Overriding Methods In this tutorial, you'll learn how overriding methods work and how to override a method in the parent class from a child class. www.pythontutorial.net Introduction to Python overridding method overriding method(재정의하는 메서드)를 사용하면 sub 클래스가 parent 클래스 중 하나에서 이미 제공하는 메서드의 특정 구현을 제공할 수 있습니다. overriding me.. 2023. 4. 4.
inheritance 출처 : https://www.pythontutorial.net/python-oop/python-inheritance/ An Essential Guide To Python Inheritance By Practical Examples In this tutorial, you'll learn about Python inheritance and how to use the inheritance to reuse code from an existing class. www.pythontutorial.net Introduction to the Python inheritance 상속을 사용하면 클래스가 기존 클래스의 논리를 다시 사용할 수 있습니다. 다음과 같은 Person 클래스가 있다고 가정합니다 class Perso.. 2023. 4. 4.
delete-property 출처 : https://www.pythontutorial.net/python-oop/python-delete-property/ How to Delete a Property from an Object in Python In this tutorial, you'll learn how to use the property() class to delete the property of an object. www.pythontutorial.net Python Delete Property 클래스의 property을 만들려면 @property 데코레이터를 사용합니다. 내부적으로 @property 데코레이터는 setter, getter 및 deleter의 세 가지 메서드가 있는 property 클래스를 사용합니다. dele.. 2023. 4. 4.
readonly-property 출처 : https://www.pythontutorial.net/python-oop/python-readonly-property/ Python Readonly Property in this tutorial, you'll learn how to define Python readonly property and how to use it for computed property and caching. www.pythontutorial.net Introduction to the Python readonly property readonly property을 정의하려면 getter만 있는 속성을 만들어야 합니다. 그러나 항상 private attribute(_age)에 액세스하여 변경할 수 있으므로 진정한 읽기 전용이.. 2023. 4. 4.
properties 출처: https://www.pythontutorial.net/python-oop/python-properties/ Introduction to class properties 다음은 이름과 나이라는 두 가지 속성이 있는 Person 클래스를 정의하고 Person 클래스의 새 인스턴스를 만듭니다. class Person: def __init__(self, name, age): self.name = name self.age = age john = Person('John', 18) age는 Person 클래스의 인스턴스 속성이므로 다음과 같이 새 값을 할당할 수 있습니다. john.age = 19 다음 할당도 기술적으로 유효합니다. john.age = -1 그러나 나이는 의미상 올바르지 않습니다. 나이가 0 .. 2023. 4. 4.
__del__ Method 출처 : https://www.pythontutorial.net/python-oop/python-__del__/ Python __del__ In this tutorial, you will learn about the Python __del__ special method and understand how it works. www.pythontutorial.net Introduction to the Python __del__ method Python에서 garbage collector(가비지 수집기)는 메모리를 자동으로 관리합니다. 가비지 수집기는 참조되지 않은 개체를 삭제합니다. 객체가 __del__ 메서드를 구현하는 경우 Python은 가비지 수집기가 객체를 파괴하기 직전에 __del__ 메서드를 호출합.. 2023. 4. 4.
Dependency Inversion Principle 출처 : https://www.pythontutorial.net/python-oop/python-dependency-inversion-principle/ Python Dependency Inversion Principle In this tutorial, you'll learn about the Python dependency inversion principle. www.pythontutorial.net Introduction to the dependency inversion principle SOLID는 Uncle Bob에 의한 5 가지 소프트웨어 디자인 원칙을 나타내는 약어입니다. S – Single responsibility Principle O – Open-closed Principle L – Li.. 2023. 4. 4.
__bool__ Method 출처 : https://www.pythontutorial.net/python-oop/python-__bool__/ Introduction to the Python __bool__ method 사용자 지정 클래스의 개체는 부울 값과 연결됩니다. 기본적으로 True로 평가됩니다. 예를 들어: class Person: def __init__(self, name, age): self.name = name self.age = age if __name__ == '__main__': person = Person('John', 25) print(bool(person)) # True 이 예제에서는 Person 클래스를 정의하고, 개체를 인스턴스화하고, 해당 부울 값을 표시합니다. 예상대로 person 개체는 True입니.. 2023. 4. 3.
__hash__ Method 출처 : https://www.pythontutorial.net/python-oop/python-__hash__/ Hash? 해시란 단방향 암호화 기법으로 해시함수를 이용하여 고정된 길이의 비트열로 변경한다. (여기서 단방향 암호화 기법은 암호화는 수행하지만 복호화는 불가능한 알고리즘을 말한다.) 이때 매핑 전 원래 데이터의 값을 키, 매핑 후 데이터의 값을 해시값, 매핑하는 과정을 해싱, 해시값+데이터색인 주소를 해시테이블이라고 한다. Hashable? 수명 주기 동안, 결코 변하지 않는(immutable) 해시값을 갖고 있고(__hash__ method), 다른 객체와 비교할 수 있으면(__eq__ method) 객체를 해시가능하다고 한다. 동일(==)하다고 판단되는 객체는 반드시 해시값이 동일해야 .. 2023. 4. 3.