YOU DOWN WITH

OOP?

Women In Technology

 

Lecturer Gant Laborde

& YOU!

Who are you?

Today Schedule

  • 10:00 - 10:15 - Check in and get coffee
  • 10:15 - 11:30 - Workshop
  • 11:30 - 11:50 - Break
  • 11:50 - 12:50 - Workshop
  • 12:50 - 1pm - Final remarks, Survey

Mission

To not only show Object Oriented Programming, but to provide the reasoning and feel the solution actually solve a real world problem for software as a paradigm.

Overview

  • Other Options
  • Advantages of OOP
  • Basics
  • Inheritance
  • Polymorphism
  • Abstraction

WARNING:

JavaScript in this workshop is ES6

Procedural Programming

Procedural Programming

 

Top Down

What's the Drawback?

Software Reactivity

  • Maintaining
  • Automatic Memory Management
  • No security of code
  • No teamwork in code
  • Maintaining
  • Automatic Memory Management
  • No security of code
  • No teamwork in code

Imagine the above as an english essay.

How do we solve this?

Object Oriented Programming

A strategy for breaking code into parts.

The Classic OOP Car

Let's Make it Happen

Encapsulation

Procedural

OOP

Functional

OOP oh so Classy

Classes & Objects

Objects are instances of classes

Tire Class

Tire Objects

Let's Code

Ruby

class Cup

  def initialize
    puts "I'm alive! *SPARKLE*"
    @drink_amount = 0
  end

  def fill
    puts "I'm filled up!"
    @drink_amount = 100
  end

  def empty
    puts "ALL GONE!"
    @drink_amount = 0
  end

  def quantity
    puts @drink_amount
    @drink_amount
  end

end

Constructor

Class

Methods

Let's Code

Java

Constructor

Class

Methods

public class Cup {

  public int drinkAmount = 0;

  public Cup() {
    System.out.println("I'm alive! *SPARKLE*");
    drinkAmount = 0;    
  }

  public void fill () {
    System.out.println("Fill'er up!");
    drinkAmount = 100;
  }

  public void empty () {
    System.out.println("Dump it!");
    drinkAmount = 0;
  }

  public int quantity () {
    System.out.println(drinkAmount.toString() + " is left");
    return  drinkAmount;
  } 

}

Let's Code

JavaScript ES6

Constructor

Class

Methods

class Cup {
  
  constructor() {
    console.log("I'm alive!")
    this.drinkAmount = 0
  }

  fill () {
    console.log('Cup fillled up')
    this.drinkAmount = 100
  }

  empty () {
    console.log('Cup emptied')
    this.drinkAmount = 0
  }

  quantity () {
    console.log(`${this.drinkAmount} drink left`)
    return  this.drinkAmount
  }   

}

Let's Code

JavaScript ES6

JS Bin

https://jsbin.com/buwucuk/1/edit?js,console

Let's Code

Ruby FYI

Now you!

use JSBin and make an object

Make them different!

Static / Class Methods

Functionality built into design

What does this give us?

Volume Helper

Ruby

  def self.volume radius, height
    puts Math::PI * radius**2 * height
  end

Volume Helper

JavaScript ES6

  static volume(radius, height) {
    const volume = Math.PI * Math.pow(radius, 2) * height
    console.log(volume)
  }

https://jsbin.com/buwucuk/3/edit?js,console

Inheritance

Taking on the functionality of an existing class

What does this give us?

Inheritance

Taking on the functionality of an existing class

import disney.pocahontas.plot;

public class Avatar extends pocahontas {
  public plot() {
    setTimeEra("Future");
    setPlanet("NotEarth");
  }
}

Inheritence

Cup Example

With Ruby

class MojoCup < Cup

  def initialize
    super
    puts "Welcome to Mojo Coffee!"
  end

end

Inheritence

Cup Example

With JavaScript ES6

class MojoCup extends Cup {
  
  constructor() {
    super()
    console.log('Welcome to Mojo')
  }
  
}

https://jsbin.com/buwucuk/2/edit?js,console

Base Class

Superclass

Inherited Class

Subclass

Now You Try

With your JSBin Create a class and extend it!

What happens when...

a subclass implements the same method as its superclass?

Polymorphism

Objects Behaving

let shape = new Square()

let shape = new Triangle()

shape.draw()

What does this give us?

Others?

  • Cups
  • Car Doors
  • Animals

Abstraction Philosophy

Circle

A cirlce is a geometric shape with known properties.  

Wheel

An abstraction based on circle with some known physical properties

Based on wheel and perhaps could have an instance.

Goodyear Tire

What does this give us?

Objects MisBehaving

let shape = 5

let shape = new Triangle()

shape.draw()

Abstract Objects

class Square extends Shape {
    String draw() {
        return "Square";
    }
}

class Triangle extends Shape {
    String draw() {
        return "Triangle";
    }
}
abstract class Shape {
    abstract String draw();
}
void showEveryone(final Shape shape) {
    println(shape.draw());
}

int main() {
    showEveryone(new Square());
    showEveryone(new Triangle());
}

Abstract means you can't create an instance

That's some opinion!

Keep it focussed on the project.

you can always extend it to add functionality!

or can you?....

Sealed && Final

C# and Java

That can be a pretty big decision

Static Typed Languages

Static Type Checking

Name some static typed languages?

Dynamic languages?

Destructor methods?

Interfaces

Enforcing common ground

Whatever you do, you must implement .draw

Interfaces exist in

Ada, C#, D, Dart, Delphi, Go, Java, Logtalk, Object Pascal, Objective-C, PHP, Racket, Seed7, Swift

 

...and more!

Interfaces vs Abstract

Examples

https://github.com/GantMan/furry_destroyer

 

https://github.com/IconoclastLabs/rubytrivia

Call to Action!

Where can you practice these skills?

Closing up

Final Remarks + Survey