Over CSC148 so far, I learned a lot of object-oriented programming concepts that I did not learn about in high school and programming on my own time. However, I did learn most of the simpler concepts in CSC108.
Objects are the most basic unit of object oriented programming. Objects are made up of data and functions that operate on data that are bundled as an unit. It is a unique instance of a data structure that's defined by its class. An object comprises class variables, instance variables and methods. A class variable is a variable that is shared by all instances of a class. Class variables are defined in a class. A instance variable is a variable that is defined inside a method and belongs only to the current instance of a class. Both these variables can be used in a method to adjust values and to return values. A method is a function that is defined in a class definition.
Classes were gone over in class too. When you define a class you define the instructions for an object, a python class has exact specifications. Classes may contain variable definitions and methods, or subroutines that can be run by the corresponding object. To create a class you write "class InsertNameHere():" and from there you can add methods to add additional function. The professor also taught inheritance. One of the most useful aspects of object-oriented programming is code re-usability. As it's name suggests inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class. To declare that we are extending a super class we write "class NewClass(SuperClass):." We can also add methods and attributes to specialize the class. The base class is basically the parent and the derived class is the child.
No comments:
Post a Comment