Lecture13-ClassImplementation-Part1-3pp

The class becomes dicult to maintain and vulnerable

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rea(self): return 2*self.radius*self.radius • A local variable exists for the duraDon of a funcDon or method call •  self.radius is not a local variable. It is an instance variable. It exists for as long as the instance of the class does, and can be accessed anywhere inside it. 19 TesGng a Class • Test your class is implemented correctly by using each method with different kinds of arguments • You can write tesDng code in the same Python file as your class, or in another file by imporDng the class • ie. to test the Person class in the file person.py, use from person import Person! • Note that imporDng a .py file also runs it!! 20 TesGng the Circle class from circle import Circle c1 = Circle(5) c2 = Circle(3) class Circle: def __init__(self, radius = 1): self.radius = radius print(c1.get_area()) print(c2.get_perimeter()) def get_area(self): return (self.radius**2)*math.pi def getPerimeter(self): return 2*self.radius*math.pi 21 7 13 ­11 ­13 Data Hiding • Python lets you do c.radius = 6 when using the Circle class, however it is not co...
View Full Document

This document was uploaded on 03/02/2014.

Ask a homework question - tutors are online