Difference between revisions of "OOP Class6"
Line 8: | Line 8: | ||
an example of how you don't need to know how all of the classes work just how to use them | an example of how you don't need to know how all of the classes work just how to use them | ||
+ | |||
+ | <!-- | ||
==Shared Members - static members== | ==Shared Members - static members== | ||
aka Shared Properties | aka Shared Properties | ||
Line 38: | Line 40: | ||
+ | |||
+ | --> | ||
==OverLoading== | ==OverLoading== | ||
Line 159: | Line 163: | ||
</csharp> | </csharp> | ||
− | you can overload the contructor forever as long as each | + | you can overload the contructor forever as long as each overload has a unique '''argument signature'''\ |
+ | |||
+ | <!-- | ||
==Operator Overloading== | ==Operator Overloading== | ||
Line 462: | Line 468: | ||
[[OOP Full Dog Diagram]] | [[OOP Full Dog Diagram]] | ||
+ | |||
+ | --> | ||
==Pair Programming== | ==Pair Programming== | ||
Line 490: | Line 498: | ||
==Homework== | ==Homework== | ||
+ | |||
+ | <!-- | ||
use Pair Programming to make tests and classes from the following UML | use Pair Programming to make tests and classes from the following UML | ||
Line 498: | Line 508: | ||
Create a UML Diagram of your c# classes (not the tv and radio yeah the pong machine and ninja and kungfumonkey and stuff) | Create a UML Diagram of your c# classes (not the tv and radio yeah the pong machine and ninja and kungfumonkey and stuff) | ||
+ | --> | ||
===READ=== | ===READ=== | ||
+ | <!-- | ||
Chapter 2 Introducin the UML in The Unified Modeling Language Users Guided (hand out) | Chapter 2 Introducin the UML in The Unified Modeling Language Users Guided (hand out) | ||
Chapter 4 Classes in The Unified Modeling Language Users Guided (hand out) | Chapter 4 Classes in The Unified Modeling Language Users Guided (hand out) | ||
+ | --> | ||
+ | |||
+ | Finish you tv radio class and add overloads to you example class | ||
quiz #2 next week | quiz #2 next week |
Revision as of 00:08, 17 October 2007
Real barking dogs...
an example of how you don't need to know how all of the classes work just how to use them
OverLoading
You can overload a method to make it more flexible.
Simple Bark Method
<csharp> public class Dog {
public string Name; // the dog's name
public string BarkSound; // the sound of the dog's bark
public Dog() { BarkSound = "Woof!!!"; }
public string Bark() { string strBark = this.BarkSound;
barkCount ++; return strBark;
}
public void Eat() { //put eat code here } } </csharp>
overloaded method that makes a dog bark more than once.
<csharp> public class Dog {
public string Name; // the dog's name
public string BarkSound; // the sound of the dog's bark
public Dog() { BarkSound = "Woof!!!"; }
public string Bark() { string strBark = this.BarkSound;
barkCount ++; return strBark;
}
public string Bark(int numBarks) { string strBark = "";
for(int i =0; i < numBarks; i++) //bark many times { strBark += this.BarkSound; barkCount ++; } return strBark;
} } </csharp>
You can overload a method as much as you want as long as each overload has a unique argument signature
Overload Constructor
Overloading the constructor of you class can make it easier to use.
here is a simple dog contructor
<csharp> public class Dog {
public string BarkSound; // the sound of the dog's bark
public Dog() { BarkSound = "Woof!!!"; }
} </csharp>
we can modify this so that we can pass in the sound of the dogs bark when the object is created
<csharp> public class Dog {
public string BarkSound; // the sound of the dog's bark
public Dog(string newBarkSound) { this.BarkSound = newBarkSound; }
} </csharp>
or the name of the dog and the barksound
<csharp>
public class Dog
{
public string BarkSound; // the sound of the dog's bark
public string Name;
public Dog(string newBarkSound, string NewName) { this.BarkSound = newBarkSound;
this.Name = newName;
}
} </csharp>
you can overload the contructor forever as long as each overload has a unique argument signature\
Pair Programming
We are going to pair off to do our next assignment. Many of the paired programming principles come from XP (http://www.extremeprogramming.org/ Extreeme Progamming)
Pairs are good because
- Pairs keep each other on track
- A partner can help when you are stuck
- Keep each other accountable
Some XP Principles
Fail - If you are having trouble succeeding fail.
Baby Steps - Do the smallest thing that you possible can that moves you in the right direction
If you do decide to dive and conqure the problem please remember that integration process is unpredictable and can be quite difficult. Try to integrate your code often. Try posting up your code and emailing or plan on meeting several times.
When two pair programmers are together one you should sit a one computer (yeah that right two of you at one computer) and one should type while the other watches and reflects. Feel free to slide the keyboard back and forth when someone get tired, stuck or has a new idea.
I would like you and your paired partner to create and demonstate classes in c# from the diagram below.
Homework
READ
Finish you tv radio class and add overloads to you example class quiz #2 next week