tulsa.net user group intro to object oriented programming

22
Tulsa .NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Upload: matthew-lyons

Post on 12-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Tulsa .NET User GroupINTRO TO OBJECT ORIENTED PROGRAMMING

Page 2: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

DisplayAboutMe(host);>Sean Whitesell

President of Tulsa .NET User Group

Sr. Developer at OpenLink Financial

[email protected] @seanw122

Page 3: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Special thanks to…

Page 4: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

What is OOP?•Object Oriented Programming•Creation of Classes and Interfaces•Polymorphism

Page 5: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

But first, a challenge• POKER HANDS

• Import file

• Each line is cards for both players

• Each line is a round

• Determine winner of each round using poker rules for comparing hands.

• Determine how many times player 1 wins

Player 1 Player 2

Round 1 2C AD JH TC 5S 2S 4H JH 3D 2D

Round 2 6H 7D 8H 9C TS 8D 3S 5D 5C AH

Round 3 4H AS JS QS QC 8C 8H 3S TH 9D

Page 6: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Poker Challenge

•projecteuler.net/problem=54

•Test project file on that page

• Judging by me supplying a new file to your code

• I’ll know how many times player 1 should win

• Judged by correct answer, speed, then code.

•Submit executable and source code.

Page 7: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Example from site

Hand   Player 1   Player 2   Winner

1   5H 5C 6S 7S KDPair of Fives   2C 3S 8S 8D TD

Pair of Eights   Player 2

2  5D 8C 9S JS AC

Highest card Ace  2C 5C 7D 8S QH

Highest card Queen

 Player 1

3  2D 9C AS AH AC

Three Aces  3D 6D 7D TD QD

Flush with Diamonds

 Player 2

4

 

4D 6S 9H QH QCPair of QueensHighest card

Nine

 3D 6D 7H QD QSPair of Queens

Highest card Seven 

Player 1

2H 2D 4C 4D 4SFull House

With Three Fours 

3C 3D 3S 9S 9DFull House

with Three Threes 

Player 1

Page 8: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Rules for Comparing Hands

High Card: Highest value card.

One Pair: Two cards of the same value.

Two Pairs: Two different pairs.

Three of a Kind: Three cards of the same value.

Straight: All cards are consecutive values.

Flush: All cards of the same suit.

Full House: Three of a kind and a pair.

Four of a Kind: Four cards of the same value.

Straight Flush: All cards are consecutive values of same suit.

Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.

Page 9: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Object

Oriented

Programming

And you

Page 10: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING
Page 11: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Object

Properties

Page 12: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Dog Cat

Lion Horse

Animal

Page 13: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Houses

Villa

Page 14: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Contacts

Vendors

Page 15: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

House

Building “Is A”

Inheritance

Page 16: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

House

Room

Composition“Has A”

Room cannot exist without a house

Page 17: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

House

Occupant

Aggregation“Has A / An”

The two objects can exist independently.

Page 18: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Public void SolveChallenge(){

var foo = File.OpenText(“C:\\temp\\poker.txt”;

foreach ( var line in foo){

blah blah}

compare each card….

is Royal Flush

is Straight Flush

is Four of a Kind

is Straight

is Three of a Kind

……}

Don't Do

This!

Page 19: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Main Class

Card

Player Hand

Winner

Page 20: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

http://faculty.orangecoastcollege.edu/sgilbert/book/03-4-ObjectOrientedConcepts-B/index.html

Polymorphism allows objects to

behave differently

Page 21: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Ship ( IShipMethod)

IShipMethod

USPS

UPS

FedEx

Page 22: Tulsa.NET User Group INTRO TO OBJECT ORIENTED PROGRAMMING

Pay( IPaymentMethod) IPaymentMethod

Visa

Mastercard

PayPal