Wednesday, October 23, 2013

Day 2 Recap -- Getting # on OOP

Today we covered some higher level concepts of Object Oriented Programming. The main ones we focused on were inheritance, encapsulation, data hiding and polymorphism.

The most complex of the three was polymorphism. Essentially you put an instance of a child variable inside of a parent variable's instance. Only the parts of the child variable that the parent can understand (like overridden methods, or properties) are accessible.

In the process we saw some C# and got examples of class creation, child class creation, instantiating a class, writing(simple) functions and calling them.

Creating a class
public class Coder{
     public string Name{set;get;}
     public string Language{set; get;}
     public int Age{set; get;}
}
Creating a new instance of a Class
Coder p = new Coder();
using dot notation to set variables for the new instance
p.name="Alex";
p.Language="C#";
p.Age=27;


public void Code(){
Console.WriteLine("Someone is coding");
}
calling the function
Code();

No comments:

Post a Comment