Object-Oriented Programming is a language model that uses “objects”, which are instances of classes. An object is an abstract data type, and it combines both information (data), and operations (code). Graph below show the OOP.

Structuring of OOP:
Classes
- think of attributes and behaviour of your new class
- identify noun (this is a candidate for class name)
- identify verbs the noun uses (candidates for behaviour of the class)
- identify less-important nouns (candidates for attributes of the class)
Methods
- may compute and report some property related to a class instance
- may change (AKA mutate) some properties of the instance (ex: the __init__ function)
- they are attached to a class instance, and they use information from that instance to do their work
Special Methods
__eq__
- used to check whether some object is equivalent to another object
· __str__
- creates a str representation that is easy to understand
- note: if you do not implement __str__, Python will use __repr__ in its place
· __repr__
- evaluate the str representation into an equivalent instance, so that you can examine it
没有评论:
发表评论