Soumettre la recherche
Mettre en ligne
Basic Mechanism of OOPL
•
2 j'aime
•
6,048 vues
K
kwatch
Suivre
(English) Basic mechanism of Object-Oriented Program Language.
Lire moins
Lire la suite
Technologie
Signaler
Partager
Signaler
Partager
1 sur 31
Télécharger maintenant
Télécharger pour lire hors ligne
Recommandé
Introduction To Javascript
Introduction To Javascript
Rajat Pandit
Inheritance patterns
Inheritance patterns
Luke Smith
Object Oriented Programming in js
Object Oriented Programming in js
threepointone
Jscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScript
jeffz
front-end dev
front-end dev
Paul Comanici
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
Oop07 6
Oop07 6
schwaa
The Evolution of Async-Programming on .NET Platform (TUP, Full)
The Evolution of Async-Programming on .NET Platform (TUP, Full)
jeffz
Recommandé
Introduction To Javascript
Introduction To Javascript
Rajat Pandit
Inheritance patterns
Inheritance patterns
Luke Smith
Object Oriented Programming in js
Object Oriented Programming in js
threepointone
Jscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScript
jeffz
front-end dev
front-end dev
Paul Comanici
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
Oop07 6
Oop07 6
schwaa
The Evolution of Async-Programming on .NET Platform (TUP, Full)
The Evolution of Async-Programming on .NET Platform (TUP, Full)
jeffz
Pure function And Functional Error Handling
Pure function And Functional Error Handling
Gyooha Kim
Lecture 03
Lecture 03
Nguyen Thanh Xuan
Joose @jsconf
Joose @jsconf
malteubl
不自然なcar/ナチュラルにconsして
不自然なcar/ナチュラルにconsして
mitsutaka mimura
JavaScript Patterns
JavaScript Patterns
Giordano Scalzo
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum
Core java concepts
Core java concepts
kishorethoutam
Javascript the Language of the Web
Javascript the Language of the Web
andersjanmyr
Oop 1
Oop 1
dreamhahaman
Swift 3 Programming for iOS : Protocol
Swift 3 Programming for iOS : Protocol
Kwang Woo NAM
Javascript foundations: Introducing OO
Javascript foundations: Introducing OO
John Hunter
Lesson19 Maximum And Minimum Values 034 Slides
Lesson19 Maximum And Minimum Values 034 Slides
Matthew Leingang
2010 08-19-30 minutes of python
2010 08-19-30 minutes of python
Kang-Min Wang
Xsl Tand X Path Quick Reference
Xsl Tand X Path Quick Reference
LiquidHub
6.1.1一步一步学repast代码解释
6.1.1一步一步学repast代码解释
zhang shuren
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Alexander Granin
Learning stochastic neural networks with Chainer
Learning stochastic neural networks with Chainer
Seiya Tokui
Functional Programming in C++
Functional Programming in C++
sankeld
Prototype
Prototype
Aditya Gaur
Cascon2011_5_rules+owl
Cascon2011_5_rules+owl
ONTORULE Project
Introduction to Scala
Introduction to Scala
Brian Hsu
Python advance
Python advance
Mukul Kirti Verma
Contenu connexe
Tendances
Pure function And Functional Error Handling
Pure function And Functional Error Handling
Gyooha Kim
Lecture 03
Lecture 03
Nguyen Thanh Xuan
Joose @jsconf
Joose @jsconf
malteubl
不自然なcar/ナチュラルにconsして
不自然なcar/ナチュラルにconsして
mitsutaka mimura
JavaScript Patterns
JavaScript Patterns
Giordano Scalzo
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum
Core java concepts
Core java concepts
kishorethoutam
Javascript the Language of the Web
Javascript the Language of the Web
andersjanmyr
Oop 1
Oop 1
dreamhahaman
Swift 3 Programming for iOS : Protocol
Swift 3 Programming for iOS : Protocol
Kwang Woo NAM
Javascript foundations: Introducing OO
Javascript foundations: Introducing OO
John Hunter
Lesson19 Maximum And Minimum Values 034 Slides
Lesson19 Maximum And Minimum Values 034 Slides
Matthew Leingang
2010 08-19-30 minutes of python
2010 08-19-30 minutes of python
Kang-Min Wang
Xsl Tand X Path Quick Reference
Xsl Tand X Path Quick Reference
LiquidHub
6.1.1一步一步学repast代码解释
6.1.1一步一步学repast代码解释
zhang shuren
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Alexander Granin
Learning stochastic neural networks with Chainer
Learning stochastic neural networks with Chainer
Seiya Tokui
Functional Programming in C++
Functional Programming in C++
sankeld
Prototype
Prototype
Aditya Gaur
Tendances
(19)
Pure function And Functional Error Handling
Pure function And Functional Error Handling
Lecture 03
Lecture 03
Joose @jsconf
Joose @jsconf
不自然なcar/ナチュラルにconsして
不自然なcar/ナチュラルにconsして
JavaScript Patterns
JavaScript Patterns
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Core java concepts
Core java concepts
Javascript the Language of the Web
Javascript the Language of the Web
Oop 1
Oop 1
Swift 3 Programming for iOS : Protocol
Swift 3 Programming for iOS : Protocol
Javascript foundations: Introducing OO
Javascript foundations: Introducing OO
Lesson19 Maximum And Minimum Values 034 Slides
Lesson19 Maximum And Minimum Values 034 Slides
2010 08-19-30 minutes of python
2010 08-19-30 minutes of python
Xsl Tand X Path Quick Reference
Xsl Tand X Path Quick Reference
6.1.1一步一步学repast代码解释
6.1.1一步一步学repast代码解释
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Learning stochastic neural networks with Chainer
Learning stochastic neural networks with Chainer
Functional Programming in C++
Functional Programming in C++
Prototype
Prototype
Similaire à Basic Mechanism of OOPL
Cascon2011_5_rules+owl
Cascon2011_5_rules+owl
ONTORULE Project
Introduction to Scala
Introduction to Scala
Brian Hsu
Python advance
Python advance
Mukul Kirti Verma
Javascript
Javascript
Aditya Gaur
Introduction to functional programming using Ocaml
Introduction to functional programming using Ocaml
pramode_ce
Programming Android Application in Scala.
Programming Android Application in Scala.
Brian Hsu
Operator Overloading
Operator Overloading
Mani Singh
Master in javascript
Master in javascript
Robbin Zhao
Shiksharth com java_topics
Shiksharth com java_topics
Rajesh Verma
Fast Forward To Scala
Fast Forward To Scala
Martin Kneissl
F#3.0
F#3.0
Rodrigo Vidal
jsbasics-slide
jsbasics-slide
Peter Borkuti
Ocl 09
Ocl 09
ClarkTony
First fare 2011 frc-java-introduction
First fare 2011 frc-java-introduction
Oregon FIRST Robotics
JavaScript Programming
JavaScript Programming
Sehwan Noh
Dive into Python Class
Dive into Python Class
Jim Yeh
Ajaxworld
Ajaxworld
deannalagason
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
Charles Nutter
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!
Kel Cecil
8 polymorphism
8 polymorphism
Abhijit Gaikwad
Similaire à Basic Mechanism of OOPL
(20)
Cascon2011_5_rules+owl
Cascon2011_5_rules+owl
Introduction to Scala
Introduction to Scala
Python advance
Python advance
Javascript
Javascript
Introduction to functional programming using Ocaml
Introduction to functional programming using Ocaml
Programming Android Application in Scala.
Programming Android Application in Scala.
Operator Overloading
Operator Overloading
Master in javascript
Master in javascript
Shiksharth com java_topics
Shiksharth com java_topics
Fast Forward To Scala
Fast Forward To Scala
F#3.0
F#3.0
jsbasics-slide
jsbasics-slide
Ocl 09
Ocl 09
First fare 2011 frc-java-introduction
First fare 2011 frc-java-introduction
JavaScript Programming
JavaScript Programming
Dive into Python Class
Dive into Python Class
Ajaxworld
Ajaxworld
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
Hey! There's OCaml in my Rust!
Hey! There's OCaml in my Rust!
8 polymorphism
8 polymorphism
Plus de kwatch
How to make the fastest Router in Python
How to make the fastest Router in Python
kwatch
Migr8.rb チュートリアル
Migr8.rb チュートリアル
kwatch
なんでもID
なんでもID
kwatch
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
kwatch
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
kwatch
O/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐ
kwatch
正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?
kwatch
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
kwatch
DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!
kwatch
PHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較する
kwatch
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
kwatch
Fantastic DSL in Python
Fantastic DSL in Python
kwatch
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
kwatch
PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門
kwatch
Pretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/Mercurial
kwatch
Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -
kwatch
文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた
kwatch
I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"
kwatch
Cより速いRubyプログラム
Cより速いRubyプログラム
kwatch
Javaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジン
kwatch
Plus de kwatch
(20)
How to make the fastest Router in Python
How to make the fastest Router in Python
Migr8.rb チュートリアル
Migr8.rb チュートリアル
なんでもID
なんでもID
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
O/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐ
正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!
PHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較する
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
Fantastic DSL in Python
Fantastic DSL in Python
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門
Pretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/Mercurial
Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -
文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた
I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"
Cより速いRubyプログラム
Cより速いRubyプログラム
Javaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジン
Dernier
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
HostedbyConfluent
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
shyamraj55
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
ThousandEyes
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
Results
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
hans926745
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Alan Dix
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
HampshireHUG
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Igalia
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
naman860154
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Delhi Call girls
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
OnBoard
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
Paola De la Torre
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Scott Keck-Warren
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Miguel Araújo
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Enterprise Knowledge
Dernier
(20)
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
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.
Télécharger maintenant