0% found this document useful (0 votes)
27 views2 pages

Abir Palekar - Chapter 8 Notesheet

Uploaded by

apalekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views2 pages

Abir Palekar - Chapter 8 Notesheet

Uploaded by

apalekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 8 : Software Objects Name_________________

The Critter Caretaker program

Enduring Understanding:
Introductions of OOP and making User defined classes.
.

Targets:
● Make User defined classes.

● Understand init, str methods

● Understand self and attributes.

Outline Notes
Understanding Object-Oriented Basics
Page 219 a programming paradigm that is based on the concept of objects, which can contain data
understanding Object- and code that manipulates that data
Oriented Basics
Creating Classes, Creating a new class creates a new type of object, allowing new instances of that type to
Methods and Objects be made. Each class instance can have attributes attached to it.

Defining a Class Classes provide a means of bundling data and functionality together. Creating a new class
creates a new type of object.
defining a Method is a label that you can call on an object; it is a piece of code to execute on that object.

Instantiating an Object creating an instance of a class. When you create an instance of a class, you instantiate the
object.

Invoking a Method Helps you run a specified method from a Python script directly in a workflow.

Using Constructors
Using Constructors initializeI(assign values) to the data members of the class when an object of the class is
created
Creating a Constructor constructor is a special type of method (function) which is used to initialize the instance
members of the class.
Creating Multiple We can create a list of objects in Python by appending class instances to the list.
Objects
Using Attributes

Page 226 The python __init__ method is declared within a class and is used to initialize the attributes
Initializing Attributes of an object as soon as the object is formed.
Accessing Attributes Attributes of a class are function objects that define corresponding methods of its
instances.
Printing an Object The dir() function is a built-in Python function that can also be used to list all the attributes
and methods of an object.
Using Class Attributes and Static Methods
Page 228 Class methods can access and modify class-level attributes. They have access to the
Using Class Attributes class object and can modify class variables or create new instances of the class.
and Static Methods
Page 230 Inside a class, you should qualify all references to class attributes with the class name
Creating a Class
Attribute
Page 231 To make a method a static method, add @staticmethod decorator before the method
Creating a Static definition
Method
Page 232 You can call a static method directly from the class, without having to create an object of
Invoking a Static Method the class first.

Understanding Object Encapsulation


Page 232 It describes the idea of wrapping data and the methods that work on data within one unit
Understanding Object
Encapsulation
Page 233 Private attributes are denoted by a double underscore prefix before the attribute name
Using Private
Attributes and Private
Methods
Page 234 By using private and protected fields, developers can control the visibility and accessibility
Creating Private of class attributes and methods, preventing accidental or intentional misuse
Attributes
Page 234-235 Private attributes are intended to be accessed only within the class in which they are
Accessing Private defined
Attributes
Page 235 Creating private methods is quite simple. All we need to do is prefix the method name with
Creating Private double underscores
Methods
Page 235-236 By using the mangled name, we can invoke private methods within the class.
Accessing Private
Methods/
Page 237 The Python convention for marking a class/function/method as private is to preface it with
Respecting an an.
Object's privacy
Understanding When to Implement Privacy & Controlling Attribute Access

Page 238 You can create a property by calling property() with an appropriate set of arguments and
Creating Properties assigning its return value to a class attribute.
Page 240 Attributes of a class can also be accessed using the following built-in methods and
Accessing Properties functions.

You might also like