OO Systems and Roles Curtis "Ovid" Poe

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Advertisements

Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
Beginning Moose Houston Perl Mongers, April 10 th 2014.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Chapter 1 Object-Oriented System Development
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
Principles of Object-Oriented Software Development Object-oriented programming languages.
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Principles of Object-oriented Programming Programming Language Paradigms August 26, 2002.
Component Software Beyond Object-Oriented Programming Clements Szyperski Chapter 7 – Object versus class composition or how to avoid inheritance Alexandre.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSSE501 Object-Oriented Development
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING DATA ABSTRACTION Jehan-François Pâris
Comparison of OO Programming Languages © Jason Voegele, 2003.
MCS 270 Spring 2014 Object-Oriented Software Development.
Introduction to Object-oriented programming and software development Lecture 1.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
BIT 1003 – Presentation 7. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
OO (Object Oriented) Programming Chapter 21 IB103 Week 12.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Sayed Ahmed Computer Engineering, BUET, Bangladesh Masters from the University of Manitoba, Canada
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
Topic 11: Object-oriented Perl CSE3395 Perl Programming Camel3 chapter 12, pages perlobj, perltoot, perlbot, perlmod manpages.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
Also “open class” and other languages….  A module is a named group of methods, constants, and class variables  All classes are modules  Modules are.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
ProgLan Python Session 4. Functions are a convenient way to divide your code into useful blocks, allowing us to: order our code, make it more readable,
Object Oriented Modeling David Li CTO, DigitalSesame.
Salman Marvasti Sharif University of Technology Winter 2015.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
CSE 143 Lecture 10 Recursion reading: slides created by Marty Stepp and Hélène Martin
Fundamentals of Visual Modeling with UML Module 1: Introduction to Object Technology.
Copyright 2005, The Ohio State University CSE – Introduction to C++ Name: Shirish Tatikonda Time: T 3:30 PM Room: BE 394
Object-Oriented Programming “The Rest of the Story”, CS 4450 – Chapter 16.
CS 368 – Intro to Scripting Languages Summer 2009 Cartwright, De Smet, LeRoy Object Oriented Programming Programming Perl Chapter 12: "Objects"
Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
OOP Basics Classes & Methods (c) IDMS/SQL News
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
Traits by Nathanael Sch ä rli, St é phane Ducasse, Oscar Nierstrasz and Andrew P. Black.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Also “open class” and other languages…
Computer Science 210 Computer Organization
Object-Oriented Programming
Ruby Classes, Modules & Mixins
Topic: Functions – Part 2
Special types Objects and operators built into the language but used only in modules: Ellipsis (also “…”): used chiefly in slices in modules like numpy.
INTRODUCTION TO OOP Objective:
Types of Programming Languages
Perl Modules.
Object Oriented Practices
slides adapted from Marty Stepp and Hélène Martin
CS565 Advanced Software Development
Verified Subtyping with Traits and Mixins
slides adapted from Marty Stepp and Hélène Martin
Programming Paradigms
Review of Previous Lesson
Object-Oriented PHP (1)
Final Review B.Ramamurthy 5/8/2019 BR.
slides created by Marty Stepp
Chapter 10 :: Object Orientated Programming
Presentation transcript:

OO Systems and Roles Curtis "Ovid" Poe

Not A Tutorial "How" is easy "Why" is not

One of These Things Is Not Like The Others Simula 67 – Classes – Polymorphism – Encapsulation – Inheritance

Multiple Inheritance Perl C++ Eiffel CLOS Python

Single Inheritance C# Java Delphi Ruby Smalltalk

Inheritance Strategies Liskov Substitution Principle Strict Equivalence C3

Inheritance Alternatives Interfaces Mixins Delegation

Four Decades of Pain Code Smell – In the language itself!

B:: Object Hierarchy

A Closer Look

A Closer Look

B::PVIV Pseudo-Code B::PVIV Internals bless { pv => 'three', # usually '3' pv => 'three', # usually '3' iv => 3, iv => 3, } => 'B::PVIV';

Printing Numbers Perl my $number = 3; $number += 2; # << fits on slide # << fits on slide say <<"END"; I have $number apples END Java int number = 3; number += 2; System.out.println( "I have " "I have " + number + number + " apples" + " apples");

More Pseudo-code sub B::PV::as_string { shift->pv } sub B::IV::as_string { shift->iv } package B::PVIV; use parent qw( B::PV B::IV ); # later say $pviv->as_string; # Str say $pviv->B::IV::as_string; # Int

Systems Grow Credit: Kishorekumar 62

The Real Problem Responsibility – Wants larger classes Versus Reuse – Wants smaller classes

The Real Solution Decouple!

Solutions Interfaces Delegation Mixins

Practical Joke Needs – explode() – fuse()

Code Reuse MethodDescription ✓ Bomb::fuse() Deterministic Spouse::fuse() Non-deterministic Bomb::explode() Lethal ✓ Spouse::explode() Wish it was lethal

Ruby Mixins module Bomb def explode def explode puts "Bomb explode" puts "Bomb explode" end end def fuse def fuse puts "Bomb fuse" puts "Bomb fuse" end endend module Spouse def explode def explode puts "Spouse explode" puts "Spouse explode" end end def fuse def fuse puts "Spouse fuse" puts "Spouse fuse" end endend

Ruby Mixins class PracticalJoke include Spouse include Spouse include Bomb include Bombend joke = PracticalJoke.new() joke.fusejoke.explode

Ruby Mixins Bomb fuse Bomb explode

Ruby Mixins Bomb fuse Bomb explode irb(main):026:0> PracticalJoke.ancestors => [PracticalJoke, Bomb, Spouse, Object, Kernel]

Moose Roles package Bomb; use Moose::Role; sub fuse { say "Bomb explode"; say "Bomb explode";} sub explode { say "Bomb fuse"; say "Bomb fuse";} package Spouse; use Moose::Role; sub fuse { say " Spouse explode"; say " Spouse explode";} sub explode { say "Spouse fuse"; say "Spouse fuse";}

Moose Roles { package PracticalJoke; package PracticalJoke; use Moose; use Moose; with qw(Bomb Spouse); with qw(Bomb Spouse);} my $joke = PracticalJoke->new; $joke->fuse;$joke->explode;

Moose Roles Due to method name conflicts in roles 'Bomb' and 'Spouse', the methods 'explode' and 'fuse' must be implemented or excluded by 'PracticalJoke' … plus … the … stack … trace … from … hell

Moose Roles { package PracticalJoke; package PracticalJoke; use Moose; use Moose; with 'Bomb' => { excludes => 'explode' }, with 'Bomb' => { excludes => 'explode' }, 'Spouse' => { excludes => 'fuse' }; 'Spouse' => { excludes => 'fuse' };} my $joke = PracticalJoke->new; $joke->fuse;$joke->explode; # Bomb fuse # Spouse explode

Moose Roles { package PracticalJoke; package PracticalJoke; use Moose; use Moose; with 'Bomb' => { excludes => 'explode' }, with 'Bomb' => { excludes => 'explode' }, 'Spouse' => { 'Spouse' => { excludes => 'fuse', excludes => 'fuse', alias => { fuse => 'random_fuse' }}; alias => { fuse => 'random_fuse' }};} my $joke = PracticalJoke->new; $joke->random_fuse;

Moose Roles Class package My::Object; use Moose; with 'Does::AsYAML'; sub to_hash { …} Role package Does::AsYAML; use Moose::Role; use YAML::Syck; requires qw(to_hash); sub to_yaml { my $self = shift; my $self = shift; return Dump( return Dump( $self->to_hash $self->to_hash ); );}1;

Languages With Roles (traits) Xerox "Star" (the origin of traits in '79/'80) Self Perl 6 Perl 5 (via Moose and others) Smalltalk (Pharo) Fortress Scala Javascript (via Joose) PHP (5.4 and above) Slate

The Problem Domain 5,613 brands 6,755 series 386,943 episodes 394,540 versions 1,106,246 broadcasts … and growing rapidly

Real World Pain

Real World Pain

Real World Pain

Real World Pain

Switching to Roles

Switching to Roles package Country; use Moose; extends "My::ResultSource"; with qw( DoesStatic DoesStatic DoesAuditing DoesAuditing);

Before

After

Increased Comprehension package BBC::Programme::Episode; use Moose; extends 'BBC::ResultSet'; with qw( Does::Search::ForBroadcast Does::Search::ForBroadcast Does::Search::ByTag Does::Search::ByTag Does::Search::ByTitle Does::Search::ByTitle Does::Search::ByPromotion Does::Search::ByPromotion Does::Identifier::Universal Does::Identifier::Universal);

Conclusions Easier to understand Simpler code Safer code

Buy My Books!

Questions ?