Classes, Instances, and Attributes

A class describes how its instances are constructed and what operations they support. Each instance can hold its own state.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Construct two counters
  2. Name the responsibility of shared definitions

Construct two counters

Creating counters with values three and seven gives two objects with the same interface. Incrementing the first changes its value to four while the second stays seven when each owns its own state. Identity and value equality distinguish those objects.

Name the responsibility of shared definitions

A method can describe how any instance increments. A mutable collection stored on the class can instead be shared across instances unless another binding overrides access. Review name binding when tracing the two kinds of attribute.[1]

References

  1. Python Software Foundation, Python Tutorial: Classes ↩