Class and Object
Class and Object
DATA SCIENCE
CONTENTS
Introduction
Class
Object
Constructor and Destructor
Advantages and Disadvantages
Conclusion
Introduction
Example:
Features Method
§ Model § Start
§ Engine type § Stop
§ Color § Gear change
§ Size
If we have to access attributes and methods of class we need create object.
The keyword class is used to create a class.
Syntax :
class classname :
statements
Object
Creating Object :
obj = class_name()
Example :
Constructor and Destructor
Example :
Parametrized constructor :
The parametrized constructor takes in the parameters and sets the value.
Example :
Advantages and Disadvantages
Advantages Disadvantages
Classes provides another Misuse of class-level attributes can
functionality of this object- lead to global state issues, making
oriented programming paradigm, it difficult to reason about the
that is, inheritance. behavior of code.
Classes also help in overriding any Object-oriented concepts,
standard operator. including classes, can be
challenging for beginners to grasp.
Provides the ability to reuse the
code, which makes the program Inheritance can lead to problems
more efficient. such as tight coupling, making the
code harder to maintain and test.
Conclusion