OOP Class9

esse quam videri
Revision as of 03:20, 9 February 2016 by Jeff (talk | contribs) (Text replacement - "syntaxhighlight lang="csharp" line="1" " to "syntaxhighlight lang="csharp"")
Jump to: navigation, search


Encapulation

I forgot to show this earlier

http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class4/DogBark


PolyMorphism

Using the least specific class to increase reuse.

Review Coins

?'s

Review MotorVehicle

?'s

Motorvehicle Diagram

Oop Motorvehicle Diagram

http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace

Private instance data members - accessors

Microsoft has stared calling private variables with accessors Properties

Private class memebers the use get and set keyword to set and retrieve data. Get and set are known as accessor methods private members are helpful when you want to also do other things when a data member is changed or change the rutern value under certain conditions. C# Programmer's Reference - Accessors http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfaccessorspg.asp. Lastly accessor also make read only and write only variables possible

//private string color read/write
private string color;

public string Color
{
  get
  {
   return color;
  }
  set
  {
   color = value;
  }
}

//private string color read only
private string color;

public string Color
{
  get
  {
   return color;
  }
}


Another property that is a good candidate for a private instance data member is the dogs age

private string age;

public int Age
{
  //age can only be accessed with get there is no set accessor
  //age must be set with HappyBirthday()
  get
  {
   return age;
  }
}

public int HappyBirthday()
{
  age++;
  return age;
}

Windows forms

Events

events from a windows form or web page are handled by event handlers. Events are raised when a user interacts with interface elements and handled by the event handlers.


http://www.csharphelp.com/archives/archive253.html

Examaple of event handlers and classes

http://iam.colum.edu/oop/MotorvehicleRace.zip

private void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("button1 Clicked");
            MessageBox.Show("button1 Clicked");   
        }

Create a windows form with a button the uses your class.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsDog
{
    public partial class Form1 : Form
    {
        Dog fido;
        
        public Form1()
        {
            InitializeComponent();
            fido = new Dog();
        }

        private void btnBark_Click(object sender, EventArgs e)
        {
            lblBark.Text = fido.Bark();
        }


        public class Dog 
        {
            public string Name;		// the dog's name
            public int Age;			// the dog's age
            public int Weight;			// the dog's weight
            public string BarkSound;	// the sound of the dog's bark

            public Dog()
            {
                BarkSound = "Woof!!!";
            }

            public string Bark()
            {
                return this.BarkSound;
            }
            public void Eat()
            {
                //put eat code here 
            }
        }	
    }
}

Home Work

Create a windows form and port your classes. The form should have UI elements (buttons, dropdown, etc) that demonstrate the use of you classes.

Watch the Android App Development with Java Essential Training

You should logon to Oasis http://oasis.colum.edu First then select the training tab. Then search for 'Android App Development with Java'

  • Section 0 Introduction
  • Section 1 Getting Started


http://www.lynda.com/Android-2-tutorials/Android-App-Development-with-Java-Essential-Training