CMSC 203 Module 2 - Object-Oriented Programming PDF
Document Details
Uploaded by Deleted User
Tags
Related
- Introduction to Object-Oriented Programming (OOP) PDF
- Programming in Python for Business Analytics Lecture Notes PDF
- Programming for Business Analytics - Lecture 5 Notes PDF
- Programming 2 MEK3100 Lecture Notes PDF
- FINM 32500 Python Programming Quiz (Autumn 2024) PDF
- Starting Out with Python - Classes and Object-Oriented Programming PDF
Summary
This file is a presentation on object-oriented programming concepts, specifically covering classes, objects, methods (functions), and constructors. The presentation, part of the CMSC 203 module, outlines how these concepts work together, emphasizing how objects maintain unique states and methods define object behaviors. This is a good resource for learning about the principles of object-oriented design and coding.
Full Transcript
Classes and Object CMSC 203 – Object-Oriented Programming Module 2 Classes and Objects Classes Blueprint or template Attributes Methods Key Components Attributes Methods Creating a Class Use ‘class’ keyword followed by the class...
Classes and Object CMSC 203 – Object-Oriented Programming Module 2 Classes and Objects Classes Blueprint or template Attributes Methods Key Components Attributes Methods Creating a Class Use ‘class’ keyword followed by the class name. Define the data members and member functions. Use ___init___ () to declare which attributes each instance of the class should have. Objects An instance of a class. No memory is allocated until an object of that class is created. Creating an Object Created by calling the class as if it were a function. This process is known as instantiation Accessing Attributes and Methods Once the object is created, you can access its attributes and methods using the dot(‘.’) operator. Fields (Attributes) Variables that belong to an object and store the data or state of that object. Each object of a class has its own set of fields, which can hold different values. Purpose of Fields Allow each object to maintain its unique state. Different classes might have different attributes values. Methods (Function) Functions defined within a class that describe the behaviors or actions that objects of that class can perform. Operate on the fields of the object, Purpose of Methods Define what an object can do. For example, the start() method in the car class enables a car objects to perform the action of starting. Constructors A special method that is automatically called when a new object is created. Used to initialized the fields of the object with specific values. Has a specific name such as ___init___ in Python. Purpose of Constructors Ensures that when an object is created, it starts with a define state. It sets up the initial values of the fields based on the parameters passed during object creation. THANKS! CREDITS: This presentation template was created by Slidesgo, and includes icons by Flaticon, and infographics & images by Freepik