Thursday, 12 February 2015

Week 6

Summary of my Object-Oriented Programming concepts

Some of the concepts we covered in Object-Oriented Programming include classes, instances, methods, inheritance, recursion, etc...
An object in programming is a unique instance of a data structure that's defined by its class. It comprises both data members (class variables or instance variables that holds data associated with a class and its objects) and methods. A Class is a concrete ADT (abstract data type) and a user-defined model for an object that defines a set of attributes that characterize any object of the class. The attributes are data members as well as methods, accessed via dot notation. A class variable is a variable that is shared by all instances of a class and are defined within a class but outside any of the class's methods. An instance variable a variable that is defined inside a method and belongs only to the current instance of a class. In general, an instance is an individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle. Class inheritance is when you create a class by deriving it from a preexisting class by listing the parent class in parentheses after the new class name instead of starting from scratch. The child class inherits the attributes of its parent class, and you can use those attributes as if they were defined in the child class. A child class can also override data members and methods from the parent. An object's attributes may or may not be visible outside the class definition. For these cases, you can name attributes with a double underscore prefix, and those attributes will not be directly visible to outsiders. Another kind of

Some Important Methods:
  • __init__ ( self [,args...] ) Constructor (with any optional arguments) 
  • __del__( self ) Destructor, deletes an object 
  • __repr__( self ) Evaluatable string representation 
  • __str__( self ) Printable string representation
Some Important Functions:
  • issubclass(sub, sup) boolean function returns true if the given subclass sub is indeed a subclass of the superclass sup 
  • isinstance(obj, Class) boolean function returns true if obj is an instance of class Class or is an instance of a subclass of Class

Saturday, 7 February 2015

Week 5

This week we had our first midterm on the 4th. I think it went well. We only had one class and we covered implementation of some of the test cases in unittest and implementation of the bracket balancer. This week I'm supposed to write about my impressions of tracing recursion from week 4. I felt like tracing functions that are recursive not too hard. It's simply a matter of rewriting the function again whenever it's called. Writing a recursive function though is much harder. In our tutorial we had to write some recursive functions even though the focus was on stacks and queues. Queues, unlike stacks, are more like a lineup for coffee then a stack of papers. The first one in is the first one out unlike stack where the last one in is the first one out. Also methods for stack such as pop and push have different names for queues even though they pretty much do the same things except for with a queue. Enqueue puts an item at the front of the queue and dequeue returns and removes the last thing in the line. In our lab, one of our tasks was to create a function (one for stack and one for queue) that takes an input and adds it to the stack or queue and when 'end' is inputted, it removes and returns each element in the stack/queue. My partner and I were both successful. To wrap it up, recursion is fun to trace but not so much to do (unless you have a smart partner who knows what's up).