Difference between revisions of "OOP Class9"

esse quam videri
Jump to: navigation, search
 
(30 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:OOP]]
+
[[Category:IAM Classes]]
  
 +
==PolyMorphism==
  
 +
Using the least specific class to increase reuse.
 +
 +
==Value vs Reference Types==
 +
 +
int, float, string and most built in types are value types
 +
 +
defined classes are Reference types.
 +
 +
==Review Coins==
 +
 +
?'s
 +
 +
==Review MotorVehicle==
 +
 +
?'s
  
 
==Motorvehicle Diagram==
 
==Motorvehicle Diagram==
Line 8: Line 24:
  
 
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace
 
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
 +
 +
<syntaxhighlight lang="csharp">//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;
 +
  }
 +
}</syntaxhighlight>
 +
 +
 +
Another property that is a good candidate for a private instance data member is the dogs age
 +
 +
<syntaxhighlight lang="csharp">
 +
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;
 +
}
 +
 +
 +
</syntaxhighlight>
  
 
==Windows forms==
 
==Windows forms==
 +
 +
===Separation of Concern===
 +
https://en.wikipedia.org/wiki/Separation_of_concerns
 +
 +
Keep you Moodle Object (logic)  classes and your UI Presentation classes separate. This will probably be very different from how you handled login in form in previous classes. We will try to keep all the Model login in the Model classes and UI Logic in the Form class. This will allow us to easily move the Model classes to a different UI like the Web or XAML.
  
 
Events
 
Events
Line 20: Line 97:
 
http://iam.colum.edu/oop/MotorvehicleRace.zip
 
http://iam.colum.edu/oop/MotorvehicleRace.zip
  
<csharp>
+
<syntaxhighlight lang="csharp">
 
private void button1_Click(object sender, EventArgs e)
 
private void button1_Click(object sender, EventArgs e)
 
         {
 
         {
Line 26: Line 103:
 
             MessageBox.Show("button1 Clicked");   
 
             MessageBox.Show("button1 Clicked");   
 
         }
 
         }
</csharp>
+
</syntaxhighlight>
  
 
Create a windows form with a button the uses your class.
 
Create a windows form with a button the uses your class.
  
<csharp>
+
<syntaxhighlight lang="csharp">
 
using System;
 
using System;
 
using System.Collections.Generic;
 
using System.Collections.Generic;
Line 43: Line 120:
 
     public partial class Form1 : Form
 
     public partial class Form1 : Form
 
     {
 
     {
         Dog fido;
+
         Dog fido; //The form 'has a' dog
 
          
 
          
 
         public Form1()
 
         public Form1()
Line 53: Line 130:
 
         private void btnBark_Click(object sender, EventArgs e)
 
         private void btnBark_Click(object sender, EventArgs e)
 
         {
 
         {
             lblBark.Text = fido.Bark();
+
             lblBark.Text = fido.Bark(); //UIEvents are delegated to the model class
 
         }
 
         }
  
  
         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
 
            }
 
        }
 
    }
 
 
}
 
}
</csharp>
+
</syntaxhighlight>
  
==Home Work==
+
==XAML Example==
  
 +
Timer in XAML
 +
https://msdn.microsoft.com/en-us/library/cc189084(v=vs.95).aspx
  
  
use Pair Programming to make tests and classes from the following UML
 
  
[[OOP Students Classes Diagram]]
+
==Home Work==
 
 
If you need to add any supporting methods or properties that are not on the diagram feel free.
 
 
 
 
 
 
 
<pre>
 
Test Student()
 
  
Jeff Meyers says hello.
+
Create a windows form and port your classes. The form should have UI elements (buttons, dropdown, etc) that demonstrate the use of you classes.
StudentDiagram.Student Jeff Meyers
 
StudentID = 0000
 
0 Courses
 
  
Test Student("Matina" , "Navratilova" )
+
Get Android Studio Installed
  
Matina Navratilova says hello.
+
You wili need
StudentDiagram.Student Matina Navratilova
+
*Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html I'm still using Java 7 Java 8 also should ve fine
StudentID = 0000
+
*Android Studio http://developer.android.com/sdk/installing/index.html?pkg=studio
0 Courses
 
  
Test Student("Dan", "Rockwood")
 
  
Dan Rockwood says hello.
+
Watch the Android-Studio-First-Look https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html
StudentDiagram.Student Dan Rockwood
 
StudentID = 0000
 
0 Courses
 
  
Make Some Course
+
You should logon to Oasis http://oasis.colum.edu First then select the training tab. Then search for 'Android-Studio-First-Look'
CourseName: Object Oriented Programming CourseName: 36-1300
 
  
Add Course
+
*Section 0 Introduction
StudentDiagram.Student Dan Rockwood
+
*Section 1 Getting Started
StudentID = 0000
+
*Section 2 Exploring the User Interface (fine to watch next week)
5 Courses
+
*Section 3 Designing and Coding (fine to watch next week)
CourseName: Object Oriented Programming CourseName: 36-1300
 
CourseName: Media Theory and Design 1 CourseName: 36-1000
 
CourseName: Media Theory and Design 2 CourseName: 36-2000
 
CourseName: English 101 CourseName: 52-1000
 
CourseName: Gym 101 CourseName: 11-1111
 
StudentDiagram.Student Dan Rockwood
 
StudentID = 0000
 
4 Courses
 
CourseName: Object Oriented Programming CourseName: 36-1300
 
CourseName: Media Theory and Design 1 CourseName: 36-1000
 
CourseName: English 101 CourseName: 52-1000
 
CourseName: Gym 101 CourseName: 11-1111
 
StudentDiagram.Student Dan Rockwood
 
StudentID = 0000
 
5 Courses
 
CourseName: Object Oriented Programming CourseName: 36-1300
 
CourseName: Media Theory and Design 1 CourseName: 36-1000
 
CourseName: test 101 CourseName: 00-0000
 
CourseName: English 101 CourseName: 52-1000
 
CourseName: Gym 101 CourseName: 11-1111
 
  
Test Instructor
 
StudentDiagram.Instructor Edna Krabappel
 
FacultyID = 0000
 
1 Course
 
CourseName: English 101 CourseName: 52-1000
 
  
Test Pencil
+
https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html
StudentDiagram.Pencil.isSharp = True
 
Dan has no pencil
 
StudentDiagram.Pencil.isSharp = True
 
All work and no play makes Dan a dull student.
 
StudentDiagram.Pencil.isSharp = False
 
All work and no play makes Dan a dull student.
 
StudentDiagram.Pencil.isSharp = False
 
</pre>
 

Latest revision as of 16:31, 10 June 2019


PolyMorphism

Using the least specific class to increase reuse.

Value vs Reference Types

int, float, string and most built in types are value types

defined classes are Reference types.

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

Separation of Concern

https://en.wikipedia.org/wiki/Separation_of_concerns

Keep you Moodle Object (logic) classes and your UI Presentation classes separate. This will probably be very different from how you handled login in form in previous classes. We will try to keep all the Model login in the Model classes and UI Logic in the Form class. This will allow us to easily move the Model classes to a different UI like the Web or XAML.

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;  //The form 'has a' dog
        
        public Form1()
        {
            InitializeComponent();
            fido = new Dog();
        }

        private void btnBark_Click(object sender, EventArgs e)
        {
            lblBark.Text = fido.Bark(); //UIEvents are delegated to the model class
        }


        
}

XAML Example

Timer in XAML https://msdn.microsoft.com/en-us/library/cc189084(v=vs.95).aspx


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.

Get Android Studio Installed

You wili need


Watch the Android-Studio-First-Look https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html

You should logon to Oasis http://oasis.colum.edu First then select the training tab. Then search for 'Android-Studio-First-Look'

  • Section 0 Introduction
  • Section 1 Getting Started
  • Section 2 Exploring the User Interface (fine to watch next week)
  • Section 3 Designing and Coding (fine to watch next week)


https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html