🐍 파이썬/파이썬 기본 문법

[OOP] class 클래스 개념 및 구성요소

써니(>_<) 2022. 7. 27. 11:30

What is "Object-oriented" programming?

 

"Object-orientation" is just one of many programming paradigms 

  : Our world is made up of "things", so it is a good model of the world!

 

Practical considerations:

  -Facilitates testing(we can test the classes separately)

  -Encourages reuse(we can reuse classes defined by other people)

  -Users don’t need to know the inner workings of a class, they just rely on the public interface (= data and function attributes)

  -It is possible to hide information that users don’t need to understand

  -Class can InheritData and Behavior From Parent Class 

 

 

What is a Class? What is an Object?

- A class is like a blueprint and objects are concrete instances

- Objects of the same class have the same attributes and functions

- Everything in Python is Object ! 

 

 

Class definition

 

The type of an object is its class

 

Constructor : definining data attributes

When creating an object (a.k.a. instantiation, construction), the __init__function is called.

This is used to:

  •Define data attributes upon object creation

  •Run any other code that needs to be run upon object creation

  •The first parameter, self, points to the instance

  •Data attributes are also called instance variables

 

 

Instantiation and access to data attributes

 

Class variables (!= not instance variables)

 

Methods are Functions Defined In A Class

 

Static methods

 

 

Instance variables can be made "private"

 

So what is "self"?