Posts

Showing posts from October, 2015

Super classes, sub classes, inheritance, oh my!

 A class can be considered as something like a blueprint or a template. A class contains both attributes and behaviors, providing something like a definition for objects. In a class, there are properties, which provide the attributes for an object. Let's say you're looking to get a new smartphone. One of the first things you might do is look up the specifications of a phone. Here's a sample of some specifications you might see: Processor Operating system Display Storage RAM Rear camera Front camera Battery Size Weight Network Connectivity     Now, these are all properties of a phone that can change, depending on what brand and model you might get. Different phones have different processors, storage space, battery size, and so on. They all generally have these specifications though, or properties. Now what kind of behaviors would a phone have? Call Text Listen to music Check email Browse the internet Use apps     ...

Breaking down methods

    A method is a behavior for an object, whereas properties are the attributes of an object. If I have a class called " Dog ," I could insert a method called " Bark ." There are four parts to the header of a method: <Access Specifier> <Return Type> <Method Name>(<Parameters>) Example: public void Bark()     The " Access Specifier " allows you to determine what has access to the method from outside of the class. This allows us to keep control of our data, and not have to worry about other classes affecting it without our knowledge. Here are the following levels of access: public: Access is not restricted. Any class can use the method protected: Access is limited to the containing class or types derived from the containing class. internal: Access is limited to the current assembly. protected internal: Access is limited to the current assembly or types derived from the containing class. private: Access is limit...

Variables and properties - how do they work?

    A variable is a value that can store data. The variable itself allows datas to be stored in a specific memory location. Over time, the variable can change values, meaning you change the data stored in that location of memory.     A property is very similar to a variable, but it acts somewhat like a proxy. In classes, a variable may have restricted access, such as " private ." Because of this, other classes can't directly change the value assigned to those variables. However, you  can change the value of it through a property associated with the variable.     Within a class (which we'll call " Math "), you may have something along the following: private int aNumber = 0;     Because this variable is set as " private ," another class cannot edit it directly. If we associate a property with that variable though, we can manipulate its data through the property. So then we may have a property set up within the class as follows: ...

On sentinel values and infinite loops

    Because I found the following to be very clear in definition, I'll quote it directly - "An infinite loop is an instruction sequence that loops endlessly when a terminating condition has not been set, cannot occur, and/or causes the loop to restart before it ends." ( Source ) We see this in the form of for, do, and while statements in C#. In each of these types of loops, the contents of the loop will continue to run until a condition is met. Many times, a programmer will create a sentinel value to control how many times a loop will run. Here's an example: SENTINEL_VALUE = 0 while (SENTINEL_VALUE < 5)     print "I love programming!"     SENTINEL_VALUE++      In this example, we tell the application to print " I love programming ", then add 1 to the variable SENTINEL_VALUE , as long as SENTINEL_VALUE is less than 5. But what if we took out the line " SENTINEL_VALUE++ "? The application would print " I love pr...

Scope, visibility, and data control

    Methods sharing data is important because without it, a method is just an isolated action that doesn't return anything In some methods, we see cases where there is no data shared by the method, such as WriteLine and ReadKey. In these examples, we're not receiving data from it, but sometimes we pay pass a string or other data type into it. The "void" return type stated in the heading of a method indicates that there is no data returned from the method. As I've learned so far though, there are many, many cases where we want to receive some kind of value from the method. We want to pass data into the method, perform some kind of action, and then receive the results of the data after the action is performed on it. Without data sharing, we lose one of the fundamentals of object-oriented programming, and would be operating in a similar fashion as a structured programming language, such as C.     After much research, and sifting through conflicting view...