Python object-oriented classes and objects (2)

Classes and objects

aims

  • The concept of classes and objects
  • The relationship between class and object
  • 'Class design

. Concepts of Classes and Objects

Classes and objects are the two core concepts of object-oriented programming

1.1 Class

  • Class is a general term for a group of things with the same characteristics or behaviors. It is abstract and cannot be used directly.
  • Features are called attributes
  • Behavior is called method
  • Class is equivalent to drawing upon the manufacture of aircraft, it is a template, is responsible for creating objects
    Insert picture description here

1.2 Target

  • An object is a concrete existence created by a class and can be used directly
  • The object created by which class has the definition in which class:
    1, attribute
    2, method
  • Objects are equivalent to airplanes manufactured with drawings.
    In program development, there should be a class first, and then an object.
    Insert picture description here

02. The relationship between class and object

  • A class is a template, and an object is created based on the class template. There should be a class first, and then an object
  • There is only one class, but there can be many objects
  • Attributes may vary between different objects.
    What attributes and methods are defined in the class, and what attributes and methods are there in the object, it is impossible to have more or less

03. Class design

Before using object-oriented development, you should first analyze the requirements and determine which classes need to be included in the program!
Insert picture description here

In program development, to design a class, it usually needs to meet the following three elements:

  • The name of such things as class name satisfies the big hump nomenclature
  • What are the characteristics of things like attributes
  • What kind of behavior does things like methods have

Big hump nomenclature CapWords

  • Capitalize the first letter of each word
  • There is no underscore between words

3.1 Determination of the class name

The noun extraction method analyzes the entire business process, and the nouns that appear are usually the types found

3.2 Determination of attributes and methods

  • The characteristic description of the object can usually be defined as an attribute
  • The behavior (verb) of the object can usually be defined as a method
    prompt: the attributes or methods not involved in the requirements do not need to be considered when designing the class

Guess you like

Origin blog.csdn.net/weixin_42272869/article/details/113266292