CSC148H1 Lecture Notes - Lecture 5: Mutator Method, Init

30 views2 pages
3 Feb 2018
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

The term data encapsulation refers to hiding implementation details from the user/client. The pointer"s y coordinate. x: float y: float def __init__(self, x: float, y: float) -> none: """initalizes a pointer. """ self. set_x(x) self. y = y def _set_x(self, x: float) -> none: A setter method that checks whether it is within appropriate bounds, and if it is, then set it as self. x. Note that methods that start with _ mean that they are private methods and should not be directly called. assert 0 <= x <= 1000 self. _x = x # underscore before a variable name. # means that it is a private variable and that it. # should not be directly accessed. def _get_x(self) -> float: """ returns a float representing the x coordinate""" return self. _x. As you can see above, when an instance of the point class is initialized, the x attribute is au- tomatically passed in through the setter method, self. set x.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents