SlideShare a Scribd company logo
Submit Search
Upload
Login
Signup
Basic Mechanism of OOPL
Report
kwatch
Follow
Sep. 14, 2009
•
0 likes
•
6,040 views
1
of
31
Basic Mechanism of OOPL
Sep. 14, 2009
•
0 likes
•
6,040 views
Download Now
Download to read offline
Report
Technology
(English) Basic mechanism of Object-Oriented Program Language.
kwatch
Follow
Recommended
Introduction To Javascript
Rajat Pandit
2.1K views
•
37 slides
Inheritance patterns
Luke Smith
1.6K views
•
137 slides
Object Oriented Programming in js
threepointone
584 views
•
31 slides
Jscex: Write Sexy JavaScript
jeffz
2.8K views
•
43 slides
front-end dev
Paul Comanici
268 views
•
20 slides
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
2K views
•
64 slides
More Related Content
What's hot
Pure function And Functional Error Handling
Gyooha Kim
59 views
•
109 slides
Lecture 03
Nguyen Thanh Xuan
234 views
•
20 slides
Joose @jsconf
malteubl
5.9K views
•
57 slides
Functions Intro
John Nunemaker
580 views
•
27 slides
不自然なcar/ナチュラルにconsして
mitsutaka mimura
1.7K views
•
73 slides
JavaScript Patterns
Giordano Scalzo
3K views
•
139 slides
What's hot
(20)
Pure function And Functional Error Handling
Gyooha Kim
•
59 views
Lecture 03
Nguyen Thanh Xuan
•
234 views
Joose @jsconf
malteubl
•
5.9K views
Functions Intro
John Nunemaker
•
580 views
不自然なcar/ナチュラルにconsして
mitsutaka mimura
•
1.7K views
JavaScript Patterns
Giordano Scalzo
•
3K views
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum
•
487 views
Core java concepts
kishorethoutam
•
2.7K views
Javascript the Language of the Web
andersjanmyr
•
889 views
Oop 1
dreamhahaman
•
373 views
Swift 3 Programming for iOS : Protocol
Kwang Woo NAM
•
286 views
Javascript foundations: Introducing OO
John Hunter
•
266 views
Lesson19 Maximum And Minimum Values 034 Slides
Matthew Leingang
•
388 views
2010 08-19-30 minutes of python
Kang-Min Wang
•
285 views
Xsl Tand X Path Quick Reference
LiquidHub
•
947 views
6.1.1一步一步学repast代码解释
zhang shuren
•
1.1K views
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Alexander Granin
•
133 views
Learning stochastic neural networks with Chainer
Seiya Tokui
•
7.2K views
Functional Programming in C++
sankeld
•
1.7K views
Prototype
Aditya Gaur
•
2K views
Similar to Basic Mechanism of OOPL
Cascon2011_5_rules+owl
ONTORULE Project
1.7K views
•
48 slides
Introduction to Scala
Brian Hsu
365 views
•
109 slides
Python advance
Mukul Kirti Verma
106 views
•
54 slides
Javascript
Aditya Gaur
1.1K views
•
25 slides
Introduction to functional programming using Ocaml
pramode_ce
5.9K views
•
64 slides
Programming Android Application in Scala.
Brian Hsu
2.4K views
•
94 slides
Similar to Basic Mechanism of OOPL
(20)
Cascon2011_5_rules+owl
ONTORULE Project
•
1.7K views
Introduction to Scala
Brian Hsu
•
365 views
Python advance
Mukul Kirti Verma
•
106 views
Javascript
Aditya Gaur
•
1.1K views
Introduction to functional programming using Ocaml
pramode_ce
•
5.9K views
Programming Android Application in Scala.
Brian Hsu
•
2.4K views
Operator Overloading
Mani Singh
•
447 views
Master in javascript
Robbin Zhao
•
787 views
Shiksharth com java_topics
Rajesh Verma
•
547 views
Fast Forward To Scala
Martin Kneissl
•
1.6K views
F#3.0
Rodrigo Vidal
•
456 views
jsbasics-slide
Peter Borkuti
•
218 views
Ocl 09
ClarkTony
•
500 views
First fare 2011 frc-java-introduction
Oregon FIRST Robotics
•
1.3K views
JavaScript Programming
Sehwan Noh
•
14.8K views
Dive into Python Class
Jim Yeh
•
2.2K views
Ajaxworld
deannalagason
•
546 views
JRuby and Invokedynamic - Japan JUG 2015
Charles Nutter
•
1.6K views
Hey! There's OCaml in my Rust!
Kel Cecil
•
2.2K views
8 polymorphism
Abhijit Gaikwad
•
569 views
More from kwatch
How to make the fastest Router in Python
kwatch
4.9K views
•
66 slides
Migr8.rb チュートリアル
kwatch
3.1K views
•
64 slides
なんでもID
kwatch
1.4K views
•
42 slides
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
kwatch
4.7K views
•
20 slides
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
kwatch
34K views
•
58 slides
O/Rマッパーによるトラブルを未然に防ぐ
kwatch
48.4K views
•
61 slides
More from kwatch
(20)
How to make the fastest Router in Python
kwatch
•
4.9K views
Migr8.rb チュートリアル
kwatch
•
3.1K views
なんでもID
kwatch
•
1.4K views
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
kwatch
•
4.7K views
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
kwatch
•
34K views
O/Rマッパーによるトラブルを未然に防ぐ
kwatch
•
48.4K views
正規表現リテラルは本当に必要なのか?
kwatch
•
16.1K views
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
kwatch
•
7.6K views
DBスキーマもバージョン管理したい!
kwatch
•
57.5K views
PHPとJavaScriptにおけるオブジェクト指向を比較する
kwatch
•
6.8K views
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
kwatch
•
59.8K views
Fantastic DSL in Python
kwatch
•
12.9K views
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
kwatch
•
4.1K views
PHP5.5新機能「ジェネレータ」初心者入門
kwatch
•
22.2K views
Pretty Good Branch Strategy for Git/Mercurial
kwatch
•
1.9K views
Oktest - a new style testing library for Python -
kwatch
•
3.3K views
文字列結合のベンチマークをいろんな処理系でやってみた
kwatch
•
6.9K views
I have something to say about the buzz word "From Java to Ruby"
kwatch
•
1.3K views
Cより速いRubyプログラム
kwatch
•
5.3K views
Javaより速いLL用テンプレートエンジン
kwatch
•
4K views
Recently uploaded
CoinEZ_whitepaper.pdf
KentaAratani
21 views
•
31 slides
Regulating Generative AI - LLMOps pipelines with Transparency
Debmalya Biswas
42 views
•
16 slides
TEKART CON 2023
AdedoyinSamuel1
20 views
•
35 slides
Experts Live Europe 2023 - Ensure your compliance in Microsoft Teams with Mic...
Jasper Oosterveld
30 views
•
76 slides
who we are - values.pptx
LauraGarceran
30 views
•
5 slides
Announcing InfluxDB Clustered
InfluxData
47 views
•
30 slides
Recently uploaded
(20)
CoinEZ_whitepaper.pdf
KentaAratani
•
21 views
Regulating Generative AI - LLMOps pipelines with Transparency
Debmalya Biswas
•
42 views
TEKART CON 2023
AdedoyinSamuel1
•
20 views
Experts Live Europe 2023 - Ensure your compliance in Microsoft Teams with Mic...
Jasper Oosterveld
•
30 views
who we are - values.pptx
LauraGarceran
•
30 views
Announcing InfluxDB Clustered
InfluxData
•
47 views
The Rise of the Machines: How AI will shape our lives in 2024
Iain Martin
•
41 views
Keynote: Two years at the British Library... and counting / Alan Danskin (Bri...
CILIP MDG
•
19 views
How to DAO?
Liveplex
•
45 views
Demystifying ML/AI
Matthew Reynolds
•
22 views
Scaling out with WordPress
Konstantin Kovshenin
•
50 views
Property Graphs in APEX.pptx
ssuser923120
•
177 views
ISO Survey 2022: ISO 27001 certificates (ISMS)
Andrey Prozorov, CISM, CIPP/E, CDPSE. LA 27001
•
61 views
Elevate Your Enterprise with FME 23.1
Safe Software
•
235 views
Unleashing the Power of Modern Carpooling Apps, Inspired by BlaBlaCar
Archie Cadell
•
28 views
Roottoo Innovation V24_CP.pdf
roottooinnovation
•
22 views
UiPath Tips and Techniques for Error Handling - Session 2
DianaGray10
•
20 views
TaketoFujikawa_KES2023
Matsushita Laboratory
•
121 views
Data Integrity Trends
Precisely
•
19 views
Improving Employee Experiences on Cisco RoomOS Devices, Webex, and Microsoft ...
ThousandEyes
•
56 views
Basic Mechanism of OOPL
1.
Basic Mechanism of
Object-Oriented Programming Language 2009-09-11 : Released 2009-09-14 : Fixed makoto kuwata <kwa@kuwata-lab.com> http://www.kuwata-lab.com/ copyright© 2009 kuwata-lab.com all right reserved.
2.
Purpose ✤
Describes basic mechanism of Object-Oriented Programming Language (OOPL) ✤ Not only Perl but also Python, Ruby, Java, ... ✤ You must be familiar with terms of Object-Oriented ✤ Class, Instance, Method, Override, Overload, ... copyright© 2009 kuwata-lab.com all right reserved.
3.
Agenda ✤
Part 1. Basics about OOPL Mechanism ✤ Part 2. More about OOPL Mechanism ✤ Part 3. Case Study copyright© 2009 kuwata-lab.com all right reserved.
4.
Part 1. Basics about
OOPL Mechanism copyright© 2009 kuwata-lab.com all right reserved.
5.
Overview
Function Class obj Method Tbl func (self) { Variable ..... m1 } m2 Z: 123 m3 func (self) { ..... Instance obj Class obj Method Tbl } m2 x: 10 m3 func (self) { y: 20 Z: 456 m4 ..... } copyright© 2009 kuwata-lab.com all right reserved.
6.
Instance Object
Pointer to Class object ✤ Instance variables + Is-a pointer ✤ Instance object knows "what I am" Variable Instance obj Class obj x: 10 Hash data (in script y: 20 lang) or Struct data (in Java or C++) copyright© 2009 kuwata-lab.com all right reserved.
7.
Class Object
Class obj ✤ Class variables Method Table ( + Is-a pointer) + Parent pointer Z: 30 + Method Table Class obj Instance methods Method Table belong to Class Z: 35
8.
Method Lookup Table ✤
Method signatures(≒names) + function pointers ✤ May have pointer to parent method table Class obj Method Table func (self) { print "hello"; m1 } m2 m3 func (self, x) { return x + 1; } copyright© 2009 kuwata-lab.com all right reserved.
9.
Method Function ✤
Instance object is passed as hidden argument OOPL non-OOPL class Point { def move(self, x, y) { var x=0, y=0; self['x'] = x; def move(x, y) { self['y'] = y; this.x = x; } this.y = y; almost } equiv. p = {isa: Point, x: 0, y: 0}; } func = lookup(p, 'move'); p = new Point(); func(p, 10, 20); p.move(10, 20); copyright© 2009 kuwata-lab.com all right reserved.
10.
Difference bet. method
and function ✤ Method requires instance object ✤ Typically, instance obj is passed as 1st argument ✤ Method call is dynamic, function call is static ✤ Method signature(≒name) is determined statically ✤ Method lookup is performed dynamically (This is why method call is slower than function call) copyright© 2009 kuwata-lab.com all right reserved.
11.
Overview (again)
Function Class obj Method Tbl func (self) { Variable ..... m1 } m2 Z: 123 m3 func (self) { ..... Instance obj Class obj Method Tbl } m2 x: 10 m3 func (self) { y: 20 Z: 456 m4 ..... } copyright© 2009 kuwata-lab.com all right reserved.
12.
Conslusion ✤
Instance object knows "what I am" (by is-a pointer) ✤ Instance variables belong to instance object ✤ Instance methods belong to class object ✤ function-call is static, method-call is dynamic copyright© 2009 kuwata-lab.com all right reserved.
13.
Part 2. More about
OOPL Mechanism copyright© 2009 kuwata-lab.com all right reserved.
14.
Method Signature ✤
Method name + Argument types (+ Return type) (in static language) ✤ Or same as Method name (in dynamic language) Example (Java): Method Declaration Method Signature void hello(int v, char ch) hello(IC)V void hello(String s) hello(Ljava.lang.String;)V copyright© 2009 kuwata-lab.com all right reserved.
15.
Method Overload ✤
One method name can have different method signature Class obj Method Table hello(IC) hello(Ljava.lang.String;) copyright© 2009 kuwata-lab.com all right reserved.
16.
Method Override ✤
Child class can define methods which has same method signature as method in parent class Parent Class Method Table hello(IC) hello(Ljava.lang.String;) Child Class Method Table hello(Ljava.lang.String;) : copyright© 2009 kuwata-lab.com all right reserved.
17.
Super ✤
'Super' skips method table lookup once def m1() { Class obj super.m1(); Method Table } m1 : Instance obj Class obj Method Table x: 10 X m1 : copyright© 2009 kuwata-lab.com all right reserved.
18.
Polymorphism (1)
not used ✤ Polymorphism depends on ... used ✤ Receiver object's data type Animal a; a = new Dog(); a.bark(); ✤ Variable data type a = new Cat(); a.bark(); Determined dynamically Instance obj Class obj Method Tbl Method Func bark(...) func (self) { ..... : : } : : copyright© 2009 kuwata-lab.com all right reserved.
19.
Polymorphism (2) ✤
Polymorphism depends on ... void bark(Object o) { ... } ✤ Data type of formal args a.bark("Wee!"); ✤ Data type of actual args Determined statically Instance obj Class obj Method Tbl Method Func bark(...) func (self) { ..... : : } : : copyright© 2009 kuwata-lab.com all right reserved.
20.
"Object" class vs.
"Class" class (1) class Class "Class" extends "Object" extends Object {...} class Foo "Object" class extends Object {...} NULL "Class" class Instance obj "Foo" class x: 10 y: 20 "Foo" extends "Object" copyright© 2009 kuwata-lab.com all right reserved.
21.
"Object" class vs.
"Class" class (2) Object = new Class() "Object" is-a "Class" Foo = new Class() Instobj = new Foo() "Object" class "Class" is-a "Class" Instance is-a "Foo" NULL "Class" class Instance obj "Foo" class x: 10 y: 20 "Foo" is-a "Class" copyright© 2009 kuwata-lab.com all right reserved.
22.
Conclusion (1) ✤
Method Signature = Method Name + Arg Types ✤ Method Overload : Same method name can have different method signature ✤ Method Override : Child class can have same method signature as parent class ✤ Super : Skips current class when method lookup copyright© 2009 kuwata-lab.com all right reserved.
23.
Conclusion (2) ✤
Polymorphism ✤ Depends on Receiver's data type, Method Name, and Temporary Args' data type ✤ Not depends on Variable data type and Actual Args' data type ✤ Relation between "Object" class and "Class" class is complicated copyright© 2009 kuwata-lab.com all right reserved.
24.
Part 3. Case Study
copyright© 2009 kuwata-lab.com all right reserved.
25.
Case Study: Ruby
from ruby.h: from ruby.h: struct RBasic { struct RClass { unsigned long flags; struct RBasic basic; VALUE klass; struct st_table *iv_tbl; }; struct st_table *m_tbl; Is-a pointer VALUE super; struct RObject { }; struct RBasic basic; Parent pointer struct st_table *iv_tbl; }; Method table Instance variables copyright© 2009 kuwata-lab.com all right reserved.
26.
Case Study: Perl package
Point; sub new { my $classname = shift @_; bless() binds hash data my ($x, $y) = @_; with class name my $this = {x=>$x, y=>$y}; (instead of is-a pointer) return bless $this, $classname; } sub move_to { my $this = shift @_; Instance object is the my ($x, $y) = @_; first argument of $this->{x} = $x; instance method $this->{y} = $y; } copyright© 2009 kuwata-lab.com all right reserved.
27.
Case Study: Python
class Point(object): def __init__(self, x=0, y=0): self.x = x Instance object is the self.y = y first argument of instance method def move_to(self, x, y): self.x = x self.y = y Possible to call instance p = Point(0, 0) method as function p.move_to(10, 20) Point.move_to(p, 10, 20) Python uses function as method, and Ruby uses method as function. copyright© 2009 kuwata-lab.com all right reserved.
28.
Case Study: Java Class
obj Method Table m1 func (this) { ... } m2 func (this) { ... } Class obj Copy parent entries Method Table not to follow parent table (for performance) m1 m2 m3 func (this) { ... } copyright© 2009 kuwata-lab.com all right reserved.
29.
Case Study: JavaScript
(1) /// (1) ✤ instance.__proto__ points prototype function Animal(name) { object (= Constructor.prototype) this.name = name; } ✤ Trace __proto__ recursively /// (2) (called as 'prototype chain') Animal.prototype.bark = function() { ('__proto__' property is anim alert(this.name); } available on Firefox) name /// (3) var anim = __proto__ new Animal("Doara"); (3) Animal prototype (1) (2) prototype bark prototype this.name = name; __proto__ alert(this.name); copyright© 2009 kuwata-lab.com all right reserved.
30.
Case Study: JavaScript
(2) /// (4) /// (5) function Dog(name) { Dog.prototype.bark2 = Animal.call(this, name); dog function() { } name alert("BowWow"); }; Dog.prototype = anim; /// (6) __proto__ delete Dog.prototype.name; var dog = new Dog("so16"); (6) Dog anim (4) (5) prototype bark2 prototype Animal.call(this); __proto__ alert("BowWow"); Animal prototype prototype bark prototype this.name = name; __proto__ alert(this.name); copyright© 2009 kuwata-lab.com all right reserved.
31.
thank you
copyright© 2009 kuwata-lab.com all right reserved.