Presentation is loading. Please wait.

Presentation is loading. Please wait.

GTECH 731 Lab Session 5 Lab 4 Review, Lab 5 Intro 10/5/10 Lab 4 Review Lab 5 Overview.

Similar presentations


Presentation on theme: "GTECH 731 Lab Session 5 Lab 4 Review, Lab 5 Intro 10/5/10 Lab 4 Review Lab 5 Overview."— Presentation transcript:

1 GTECH 731 Lab Session 5 Lab 4 Review, Lab 5 Intro 10/5/10 Lab 4 Review Lab 5 Overview

2 Lab 4 – OOP OOP combines functions and data into single entity – Object Object defined by Class Variables represent current state of object Methods represent abilities of object Objects modeled through hierarchy of class inheritance Higher abstract level defines general, common characteristics belonging to all subclasses Lower level subclasses define unique characteristics not common to all objects of more abstract class Object is Instance of Class MyCat is instance of Feline namespace MyProjectName { public class Animal { public bool bHeartBeating = true; public void Walk() { // code to implement walk } public class Mammmal : Animal { public bool bWarmBlooded; public void MammalAction() { // code to implement action } public class Feline : Mammmal { public bool bFluffy; public void Feline() { bFluffy = true; } public void Purr() { // code to implement purr } class Program { static void Main(string[] args) { Feline MyCat = new Feline(); MyCat.bFluffy = false; MyCat.Walk(); MyCat.Purr(); MyCat.bWarmBlooded = true; MyCat.bHeartBeating = true; }

3 Lab 4 – Combining Variables with Methods X1, Y1, X2 and Y2 variables moved into class Line X1, Y1, X2 and Y2 => myLine.X1, myLine.Y1, myLine.X2 and myLine.Y2 X1 = e.X => myLine.X1 = e.X LineLength function copied into class Line Parameter list removed – class variables accessible within class LineLength(X1, Y1, X2, Y2) => myLine.LineLength() Both functions of same name can co-exist; distinguished by parameter list and object association Creating new Line object similar to declaring and initializing variable Line myLine = new Line(); Class “Line” instantiated as Object “myLine” myLine contains endpoint variables and LineLength method

4 Lab 5 – Object Orientation Moving towards completely self-contained Object Class All methods, including Draw, are within class definition Used Paint handler to “repaint” or redraw the image object e.Graphics.Drawline used outside of object e.Graphics sent into “Draw” method of object private void pbxImage_Paint(object sender, PaintEventArgs e) { // With OOP if (curShape != null) { curShape.Draw(e.Graphics); } private void pbxImage_Paint(object sender, PaintEventArgs e) { // Without OOP e.Graphics.DrawLine(new Pen(Color.Red, 3), myLine.x1, myLine.y1, myLine.x2, myLine.y2); } public override void Draw(Graphics g) { g.DrawLine(new Pen(Color.Red, 2), start.x, start.y, end.x, end.y); }

5 Lab 5 – Visual Studio Issues Ambiguity using same names “Geometry” namespace and “Geometry” class Point

6 Lab 5 – Visual Studio Issues Casting curShape as a LineString Object Cannot declare new LineString on every MouseUp event

7 Lab 5 – Object Overview of Lab 5 – Windows Form Only


Download ppt "GTECH 731 Lab Session 5 Lab 4 Review, Lab 5 Intro 10/5/10 Lab 4 Review Lab 5 Overview."

Similar presentations


Ads by Google