Click here to load reader

CAR 构件技术 及 ELASTOS 操作系统

Embed Size (px)

DESCRIPTION

CAR 构件技术 及 ELASTOS 操作系统. 上海科泰华捷科技有限公司 2014.8. 题外话. 谈点理论 , 谈 点技术 理论 来源于 朴素的想法和逻辑推理 理论与 实现 间 的差距. 主要内容. CAR 构件技术 技术要点 主要功能 演进方向. 主要 内容. Elastos 操作系统 系统架构 与 Android 的关系 主要特点 演进方向. CAR 构件技术. 技术要点 主要功能 演进方向. CAR 技术要点. 面向接口编程 C++ 扩展反射. 面向接口编程. 内聚度与耦合度 ( 软件度量 ) 高内聚 低耦合 - PowerPoint PPT Presentation

Citation preview

CAR & ELASTOS

CAR ELASTOS2014.8

,

CAR

ElastosAndroidCAR

CARC++()()()Listener?()??(Contract)()C++Java

C++:(,) :(,) : :, ():+ :+()

JavaJVM SpecIn some of Oracles implementations of the Java Virtual Machine, a reference to a class instance is a pointer to a handle that is itself a pair of pointers: one to a table containing the methods of the object and a pointer to the Class object that represents the type of the object, the other to the memory allocated from the heap for the object data.

*TheJava Virtual Machine Specification, Java SE 7 Edition (Java Series) [Tim Lindholm, Frank Yellin, Gilad Bracha, Alex Buckley]Java(, C++)getfieldhttp://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.getfield

// 128: aload_0// 129: getfield 93 com/google/android/location/internal/server/ServiceThread:context Landroid/content/Context;

Java(, C++)invokeinterface, invokevirtualhttp://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokeinterfacehttp://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokevirtualJava(interface)static, finalpublic abstractpublic OSGIThe Dynamic Module System for Javahttp://www.osgi.org/Main/HomePageIDC++:(Paradigm)(functional language)Lisp, Scheme, Haskell(lambda calculus):

(first class object)(binding)(assign),(side effect),:()(monad),(cps, Continuation Programming Style)

(Paradigm)(structural language)C, Pascal(object-oriented language)C++, Java, Smalltalk, Ruby

(static typing): C++, JavaString name;(dynamic typing): Smalltalk, JavaScriptname := String new asValue.(Class-based): C++, Java, Smalltalk(Prototype-based): Self, JavaScript

(Parametric polymorphism)(template): AutoPtr: str := obj toString.(Class-based)(Class)(Object): C++, Java, Smalltalk

(Prototype-based)(Object),(Class)(),(delegation): Self, JavaScript

Ungar, Smith: SELF The Power of Simplicity, Journal of Lisp and Symbolic Computation, 4/1991

Alan C. Kays principle (2003 Turing Award)Everything is an objectObjects communicate by sending and receiving messages (in terms of objects)Objects have their own memory (in terms of objects)Every object is an instance of a class (which must be an object)The class holds the shared behavior for its instances (in term of objects in a program list)To eval a program list, control is passed to the first object and the remainder is treated as its message* Kay A C. The Early History of Smalltalk[J]. ACM SIGPLAN Notices, 1993, 28(3): 69-95.(Computational reflection, Brian Cantwell Smith, 1982) , , :

B.C. Smith. Informal Proceedings of the First Workshop on Reflection and Metalevel Architectures in Object-Oriented Programming. OOPSLA-ECOOP'90, Ottawa.

(introspection)::Java(intercession)::Smalltalk

:,, :Java, Smalltalk:,,,:Smalltalk(metaclass, class-based OOPL, SmallTalk-80),, ()(New),

Jacques Ferber. Computational reflection in class based object oriented languages. In OOPSLA 89, pages 317-326. ACM SIGPLAN Notices, 24(10).(metaobject, prototype-based OOPL, 3-KRS, Pattie Maes),,,,,, ,

Pattie Maes. Concepts and Experiments in Computational Reflection. In OOPLSA 87 Proceedings, pages 147-155, 1987.

Jacques Ferber. Computational reflection in class based object oriented languages. In OOPSLA 89, pages 317-326. ACM SIGPLAN Notices, 24(10).activityWebjsp, java servlet, web containerActivityapk, PackageManagerService(pms)AndroidManifest.xml, ActivityintentStartActivity, ActivityManagerService(ams)intentpmsActivityapkAms, ActivityActivityThreadapkjar,Activity3-Lisp3-KRSCLOSSmalltalk-803-Lisp,(RPP),GGLispRPP(meta-circular interpreter)GRPP2

Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD Thesis, 19823-Lisp(simple)(reflective, )0,1RPP(G),2RPP(G)1RPP,RPPRPP3-Lisp

G.,GRPP,GRPP,RPP.,,RPP.2RPPG,1RPP2RPP,1RPP.,RPP.3-Lisp,RPP,,RPPRPP.3-KRS,,meta(referent)

Pattie Maes, Concepts and experiments in computation reflection,ACM SIGPLAN Notices, 22(12):147-155, December 19873-KRS

CLOS(Common Lisp Object System)(metaobject protocol):,,api, Gregor Kiczales,Jim des Rivieres, andDaniel G. Bobrow,The Art of the Metaobject Protocol, 1991, MIT Press.Smalltalk(metaclass):,,,,Goldberg A. and Robson D. (1983) Smalltalk-80: The Language and its Implementation. Addison-Wesley. Reading, Massachusetts. Smalltalk-80

Alan C. Kays principle (2003 Turing Award)p1. Everything is an objectp2. Objects communicate by sending and receiving messages (in terms of objects)p3. Objects have their own memory (in terms of objects)p4. Every object is an instance of a class (which must be an object)p5. The class holds the shared behavior for its instances (in term of objects in a program list)p6. To eval a program list, control is passed to the first object and the remainder is treated as its message* Kay A C. The Early History of Smalltalk[J]. ACM SIGPLAN Notices, 1993, 28(3): 69-95.Class-based OOPLObjectClass metaPremise I: Everything is an object(p1)Premise II: Class belongs to everything(axiom)Conclusion I: Every class is an object(c1)Premise III: Every object is an instance of a class(p4)Conclusion II: Every class is an instance of a class (called metaclass)(c2) recursively

Class-based OOPLObjectClass ObjectClassPremise I:Class, ClassObject, ObjectClass, ObjectPremise II:The class holds the shared behavior for its instances(p5)

SOM Metaclass Framework, Putting Metaclasses to Work

CLOS

SOM

Smalltalk-80

0RPP1RPP2RPP3Gn

(n=0)

(n=0)

RPP(n=1)

(n=0)

RPP(n=1)

RPP(n=2)

(n=0)

RPP(n=1)

(n=0)

Meta

Referent

Meta

Name

Mutation-Method

Inheritance-Method

Print-Method

Message-Handling-Method

Instantiation-Method

Meta

Referent

Type

Meta

Type

...

Type

Type

Meta

Type

Meta

Type

...

Appendix

B Source Code for

Chapter 24

This appendix shows the code for the above examples in full. To save space I've done some minor things

such as only show the class names and the instance variable names in the class definition.

Superclasses ApplicationModel subclass: #MyInput instanceVariableNames: 'person ' MyInput class>>open: aModel ^self openOn: (self new initialize: aModel) ApplicationModel subclass: #MyView instanceVariableNames: 'person ' MyView class>>open: aModel ^self openOn: (self new initialize: aModel) Model subclass: #MyPerson instanceVariableNames: 'name age '

Example One MyInput subclass: #MyInput1 instanceVariableNames: 'name age ' MyInput1>>initialize: aPerson person := aPerson. name := String new asValue. name onChangeSend: #nameChanged to: self. age := 0 asValue. age onChangeSend: #ageChanged to: self MyInput1>>age ^age MyInput1>>name ^name MyInput1>>ageChanged person age: self age value

Copyright 1997 by Alec Sharp Download more free Smalltalk-Books at: - The University of Berne: http://www.iam.unibe.ch/~ducasse/WebPages/FreeBooks.html - European Smalltalk Users Group: http://www.esug.org

Source Code for Chapter 24

2

MyInput1>>nameChanged person name: self name value MyView subclass: #MyView1 instanceVariableNames: 'name age ' MyView1>>initialize: aPerson person := aPerson. person addDependent: self. name := String new asValue. age := 0 asValue. MyView1>>age ^age MyView1>>name ^name MyView1>>update: aSymbol with: aValue from: anObject aSymbol == #name ifTrue: [self name value: aValue]. aSymbol == #age ifTrue: [self age value: aValue] MyPerson subclass: #MyPerson1 instanceVariableNames: ' ' MyPerson1>>age: aValue age := aValue. self changed: #age with: age MyPerson1>>name: aValue name := aValue. self changed: #name with: name

Example Two MyInput subclass: #MyInput2 instanceVariableNames: 'name age ' MyInput2>>initialize: aPerson person := aPerson. name := String new asValue. name onChangeSend: #nameChanged to: self. age := 0 asValue. age onChangeSend: #ageChanged to: self. MyInput2>>age ^age MyInput2>>name ^name MyInput2>>ageChanged person age value: self age value MyInput2>>nameChanged person name value: self name value MyView subclass: #MyView2 instanceVariableNames: 'name age ' MyView2>>initialize: aPerson person := aPerson. person name onChangeSend: #nameChanged to: self. person age onChangeSend: #ageChanged to: self. name := String new asValue. age := 0 asValue. MyView2>>age ^age MyView2>>name ^name MyView2>>ageChanged self age value: person age value.

Source Code for Chapter 24

3

MyView2>>nameChanged self name value: person name value. MyPerson subclass: #MyPerson2 instanceVariableNames: ' ' MyPerson2>>age ^age isNil ifTrue: [age := 0 asValue] ifFalse: [age] MyPerson2>>name ^name isNil ifTrue: [name := String new asValue] ifFalse: [name]

Example Three MyInput subclass: #MyInput3 instanceVariableNames: '' MyInput3>>initialize: aPerson person := aPerson. MyInput3>>age ^(AspectAdaptor subject: person sendsUpdates: true) forAspect: #age. MyInput3>>name ^(AspectAdaptor subject: person sendsUpdates: true) forAspect: #name. MyView subclass: #MyView3 instanceVariableNames: '' MyView3>>initialize: aPerson person := aPerson MyView3>>age ^(AspectAdaptor subject: person sendsUpdates: true) forAspect: #age. MyView3>>name ^(AspectAdaptor subject: person sendsUpdates: true) forAspect: #name. MyPerson subclass: #MyPerson3 instanceVariableNames: ' ' MyPerson3>>age ^age MyPerson3>>age: aValue age := aValue. self changed: #age MyPerson3>>name ^name MyPerson3>>name: aValue name := aValue. self changed: #name

Example Four MyInput subclass: #MyInput4 instanceVariableNames: '' MyInput4>>initialize: aPerson person := aPerson asValue MyInput4>>age | adaptor |

Source Code for Chapter 24

4

adaptor := AspectAdaptor subjectChannel: person sendsUpdates: true. adaptor accessWith: #yearsOld assignWith: # yearsOld: aspect: #age. ^adaptor MyInput4>>name | adaptor | adaptor := AspectAdaptor subjectChannel: person sendsUpdates: true. adaptor accessWith: # called assignWith: # called: aspect: #name. ^adaptor MyView subclass: #MyView4 instanceVariableNames: '' MyView4>>initialize: aPerson person := aPerson asValue MyView4>>age | adaptor | adaptor := AspectAdaptor subjectChannel: person sendsUpdates: true. adaptor accessWith: # yearsOld assignWith: # yearsOld: aspect: #age. ^adaptor MyView4>>name | adaptor | adaptor := AspectAdaptor subjectChannel: person sendsUpdates: true. adaptor accessWith: # called assignWith: # called: aspect: #name. ^adaptor MyPerson subclass: #MyPerson4 instanceVariableNames: ' ' MyPerson4>> yearsOld ^age MyPerson4>> yearsOld: aValue age := aValue. self changed: #age MyPerson4>>called ^name MyPerson4>> called: aValue name := aValue. self changed: #name

Example Five MyInput subclass: #MyInput5 instanceVariableNames: 'trigger ' MyInput5>>initialize: aPerson person := aPerson. trigger := false asValue MyInput5>>accept trigger value: true MyInput5>>age | adaptor | adaptor := AspectAdaptor subject: person sendsUpdates: true. adaptor forAspect: #age. ^BufferedValueHolder subject: adaptor triggerChannel: trigger.

Source Code for Chapter 24

5

MyInput5>>name | adaptor | adaptor := AspectAdaptor subject: person sendsUpdates: true. adaptor forAspect: #name. ^BufferedValueHolder subject: adaptor triggerChannel: trigger. MyView subclass: #MyView5 instanceVariableNames: '' MyView5>>initialize: aPerson person := aPerson MyView5>>age ^(AspectAdaptor subject: person sendsUpdates: true) forAspect: #age. MyView5>>name ^(AspectAdaptor subject: person sendsUpdates: true) forAspect: #name. Model subclass: #MyPerson5 instanceVariableNames: '' MyPerson5>>age ^age MyPerson5>>age: aValue age := aValue. self changed: #age MyPerson5>>name ^name MyPerson5>>name: aValue name := aValue. self changed: #name

Example Six MyInput subclass: #MyInput6 instanceVariableNames: '' MyInput6>>initialize: aPerson person := aPerson asValue. MyInput6>>person ^person MyView subclass: #MyView6 instanceVariableNames: '' MyView6>>initialize: aPerson person := aPerson asValue. MyView6>>person ^person Model subclass: #MyPerson6 instanceVariableNames: ' ' MyPerson6>>age ^age MyPerson6>>age: aValue age := aValue. self changed: #age MyPerson6>>name ^name MyPerson6>>name: aValue name := aValue. self changed: #name

Source Code for Chapter 24

6

Example Seven

MyInput subclass: #MyInput7 instanceVariableNames: 'trigger ' MyInput7>>initialize: aPerson person := aPerson asValue. trigger := false asValue. MyInput7>>person ^person MyInput7>>trigger ^trigger MyInput7>>accept trigger value: true. MyView subclass: #MyView7 instanceVariableNames: '' MyView7>>initialize: aPerson person := aPerson asValue. MyView7>>person ^person MyPerson subclass: #MyPerson7 instanceVariableNames: '' MyPerson7>>age ^age MyPerson7>>age: aValue age := aValue. Transcript cr; show: 'Age changed'. self changed: #age MyPerson7>>name ^name MyPerson7>>name: aValue name := aValue. Transcript cr; show: 'Name changed'. self changed: #name

Example Eight MyInput subclass: #MyInput8 instanceVariableNames: '' MyInput8>>initialize: aPerson person := aPerson. MyInput8>>age ^(PluggableAdaptor on: person) getBlock: [:model | model age] putBlock: [:model :aValue | model age: aValue * 3] updateBlock: [:model :aspect :parameter | aspect == #age] MyInput8>>name ^(PluggableAdaptor on: person) getBlock: [:model | model name] putBlock: [:model :aValue | model name: aValue asLowercase] updateBlock: [:model :aspect :parameter | aspect == #name] MyView subclass: #MyView8 instanceVariableNames: '' MyView8>>initialize: aPerson person := aPerson. MyView8>>age ^(PluggableAdaptor on: person) getBlock: [:model | model age * 10]

Source Code for Chapter 24

7

putBlock: [:model :aValue | ] updateBlock: [:model :aspect :parameter | aspect == #age] MyView8>>name ^(PluggableAdaptor on: person) getBlock: [:model | model name asUppercase] putBlock: [:model :aValue | ] updateBlock: [:model :aspect :parameter | aspect == #name ] Model subclass: #MyPerson8 instanceVariableNames: ' ' MyPerson8>>age ^age isNil ifTrue: [age := 0] ifFalse: [age] MyPerson8>>age: aNumber age := aNumber. self changed: #age MyPerson8>>name ^name isNil ifTrue: [name := String new] ifFalse: [name] MyPerson8>>name: aString name := aString. self changed: #name

Source Code forChapter 24SuperclassesExample OneExample TwoExample ThreeExample FourExample FiveExample SixExample SevenExample Eight