Friday 22 November 2013

Reduce and information hiding

This week, we learnt an entirely different topic from what we were doing in the past week. The first concept was information hiding. We prevented the user from directly manipulating the values of various variables used in the code. Instead, we made the variable private and used getters and setters to set and use its value.This helps avoids assigning of invalid inputs to the variables, as the input is validated in the setter. Other than that, it also allows us to make some variables as read-only type, by not providing the setter. Once we have all the required methods, we make a new variable as the property of this private variable, and access the getter and setter through it. I was aware about the idea of using getters and setters from my JAVA knowledge and its recent use in CSC 207. But, learnt some innovative methods of using them in this week.

The other concept introduced was reduce, which allowed us to break down any iterator to a single value, by applying an operation on pairs of items in the iterator. This is a very nice technique to extend some of the built-in functions like sum, multiplication. etc and use them in a place where they cannot be used directly. We can also define our own operations. This week,examples like multiplying the items in a list, summing a list containing lists,etc were shown. It is a very nice way of reducing the iterators, when different operations need to be done on the items.

No comments:

Post a Comment