2013年11月19日星期二

hiding attribute, equality

  In this week's lecture, we mostly covered the topic of hiding attribute, equality and reduce. Hiding attribute is somewhat similiar to a private attribute, however, there is a slight difference. It uses ._ instead of _ in the initializer. Changing an attribute of the parent, can causes change in the children's attribute as well. Also, we talked briefly about the equality, which is a build in function of python called __eq__. The equality function compares two node and see if they are equivalent, and noted that the function checks whether they are equivalent or not, instead of to check whether they are the same. It is interesting because even thought two nodes might be equivalent but it doesn't mean that they are the same. If we uses the id() to check, we can see that the two nodes have different identities. After that, we uses the build in python function property and we also create a get, set function, in this lecture we didn't create a delect function, therefore we have the delect fuction replaced with a None. If a node wasn't set in a function, which means it isn't an acceptable input of the parameter, in this case we raise an exception.

没有评论:

发表评论