19. 19 Prototype-based Programming
// JavaScript.
//"ex nihilo" object creation using the literal
var foo = {name: "foo", one: 1, two: 2};
var bar = {two: "two", three: 3};
bar.__proto__ = foo; // foo is now the prototype of bar.
bar.one // Resolves to 1.
bar.three // Resolves to 3.
bar.two; // Resolves to "two"
// bar.[[prototype]] = foo
// var bar = Object.create( foo );
foo.name; // unaffected, resolves to "foo"
bar.name; // Resolves to "foo"
Allegory of the Cave
1- False REALITY
2- Manufactured TRUTH
3- TRUTH
4- Science: To reject the unverifiable
5 دقيقه
Class:
Name
Properties: Attributes
Behavior: Methods
Class Horse{
Color {White, Black, …}
Race{Arab, ..}
Ride();
Run();
Fly() XXX;
}
Class Ball{
Color{White, Red, ..}
Substance{Leather, …}
Radius{Floating Point Numbers}
Jump();
Puncture(); ???
}
تصوير يا نام؟
چرا نام؟ ارزش نام؟
ارزش نامگذاري
5 دقيقه
Demiurge: GOD
خودش يه کلاس
Class God{}
God allah = New God();
الگوهاي طراحي:
Sigleton! توحيد
Proxy نبوت
رنگ وجود
خلق
ايجاد
آفرينش
زئوس: خداي آسمان و صلاح او آذرخش: قدرتمند ترين خدايان
5 دقيقه
ابن سينا: ما جعل الله المشمشه مشمشه، بل اوجدها
خدا زردآلو را زردآلو نکرد، بلکه آن را ايجاد کرد
ملاصدرا: هر فرد انساني خود يک مُثُل دارد (ارجاع اين جمله رو پيدا نکردم!)
من حسين هستم:
به عنوان يک مقدار از صفت نام از کلاس انسان؟
Class Human{ Name; ..}
Human a = new Human(){Name = “Hossein”}
يا يک نمونه با نام حسين؟
Human Hossein = new Human();
یا يک کلاس سينگلتون؟
Class Hossein{..}
Hossein.Create();
قرآن: و علم الادم الاسماء کلها
علم تذکاري
Meta Class: Generic Class
Class<T> Human{}
Human<Girl> Zahra = new Human<Girl>();
Human<Boy> Ali = new Human<Boy>();
Class Girl{}
Class Boy{}
Girl Zahra = new Girl();
Boy Ali = new Boy();
Static Class, Static Property
5 دقيقه
Pupil in the Plato ‘s Academy
Instructor of Alexander the Great
Studies
Physic
Metaphysic
Poetry
Zoology
Ethics
Music
…
Logic(Analytics) : New Science
Almost shape all Western & Islamic Philosophers and Scientists: Britannica: Aristotle was the first Genuine Scientist in History … Every Scientists is in his debt!
قبل از او علم وجود داشت، بعد از او شکل گرفت: دانش
After Plato death: Theoretical: Platonism Empirical : Empiricism
دانشمندان اسلامي: علوم اسلامي: المعلم الاول: The First Teacher
The Second one??
فلسفه طبيعي: پرداخت به پديده هاي دنياي طبيعي
علوم
علوم عملي Practical: سياست و اخلاق Ethics & Politics
علوم شعري Poetical: شعر و ديگر هنر ها Poetics & other fine arts
علوم نظري Theoretical: فيزيک ، رياضي و متافيزيک
گامهاي فلسفه: 1: منطق 2: علوم نظري 3: علوم عملي 4: علوم شعري
کتاب شناسي: رساله - مقاله: فيزيک، متافيزيک، اخلاق نيکوماخوسي، ساست، شعر و ارغنون(Organon: آلت درست انديشيدن) مجموعه کتاب مربوط به منطق
رساله متافيزيک: پرداخت به نظريه فرم
متافيزيک: دانش موجودت غير مادي the knowledge of immaterial beings: موجودات در بالاترين سطح از انتزاع Highest degree of abstraction
نام هاي ديگر متافيزيک : First philosophy , the theologic science
Theory of Universals:
ارسطو لغت فرم را براي چيز ديگه اي استفاده مي کند. لذا لغت يونيورسال (کلي) رو براي آن چيزي که افلاطون فرم بکار ميبرد استفاده مي کنيم:
يونيورسال بدون نمونه آن وجود ندارد.
اصالت وجود با اشياء است. نام و يا يونيورسال ذهني اند!
Real and Non-Real of “Existence”
وجود ذهني!
طريقه دستيابي به يونيورسال: با دسته بندي و Generalization از حرکت عمودي به بالا از سطوح مختلف انتزاع
کلي يک اسم مشترک که قابل انطباق بر اجزاي يک گروه و يا طبقه است: انسان، حيوان، گياه ...
کلي يک تجربه ساده ذهني است و نه امري خارجي و واقعي
کليات تصورات ذهني اند نه حقايق خارجي محسوس: آنها اسماء اند و نه اشياء
جهان ما از اشياء مشخص و جزئي تشکيل شده و نه امور کلي و مشترک
دلايلي که ارسطو به اين نظريه رسيد:
برگشت به طبيعت: سير آفاقي، نقد به آن نسيه
تغيير: تغيير در مشخصات و رفتار يک شيء(Dynamic Type)
نام ها و يونيورسالها تنها کلياتي هستند به نمايندگي اشياء براي بررسي آنها: يافت مفهوم Concept Learning
مثالهاي نقض:
ميتوان يونيورسالي داشت که حداقل يک شيء از آن هم وجود نداشته باشد؟
ميتوان اشيائي داشت که هيچ يونيورسال مشترکي نداشته باشد؟
The School of Athens, or Scuola di Atene in Italian, is one of the most famous frescoes by the Italian Renaissance artist Raphael.
Change not in property value, but also in new properties and new behaviors!
Wrapping Methods Proxy!
Death Reborn (reincarnation) : Freeze Pattern
www.Express.co.uk: amzing tale of the Inca ice maiden, human sacrifice
Inca Civilization: 13 year-old girl, 500 years old best mummy found in 1999!
Wrong Picture: Why? Family Resemblance rather than Categorization!
Categories
1- Species: گروه مستقيم که اشياء مستقيم در آن گروه قرار ميگيرند : دسته انسان: Direct Relation with Object
2- Genus: More General than Species: has relation “is a” with Species category
اگه بخوايم از يک شي تعريف ارائه بديم:
اين شي صفات مشترکي با ديگر اشياء دارد (تعلق به يک گروه يا يونيورسال) (Inheritance: Value Vs. Class)
مشخصه هايي دارد که او را از ديگر اشياء آن گروه متمايز مي سازد: وجه فصل
انسان حيواني است عاقل
سطوح مختلف انتزاع: در بالاترين سطح انتزاع : شيء Object
Interface Implementation!
Categorization Vs. Classification
Generalization Vs. Inheritance
Dynamic Type Vs. Strong Type
Dynamic Inheritance
.net 4.0
- dynamic
- var
Form (Class) Vs. Value (Instance, Object) Inheritance
Form Inheritance: behavior and property reuse
delegation: by composition or by Inheritance
Darwin: on the Origin of Species
a series of generations of concrete objects of a certain species could be developed into another species through small inter-generational changes
1- Inheritance is an act that takes place through concrete objects.
2- there must exist at least one concrete pair of parent-child, in which the parent belongs to a certain species, while its child, although he got a significant part of its properties and their values from this parent, belongs to another species.
3- Inheritance is not an ongoing process,
a one-time only activity, which ends when the child object is instantiated from the parent object.
the delegation option (a situation where a change of property value in the parent object leads to a change of value in the child object) does not exist. This is in contrast to inheritance at the abstract level (Plato), where the relations between the Forms along the hierarchy are constant, and therefore, any change in a parent will unavoidably affect its child. delegation is built-in within Forms inheritance
Needs to implement delegation in property values through inheritance!
New type by Inheritance or Extend type?
Austrian-British philosopher : 1889 - 1951
worked primarily in logic, the philosophy of mathematics, the philosophy of mind, and the philosophy of language.
taught at the University of Cambridge
Books: Philosophical Investigations
فهم درست از هر چيزي: نيازمند مطالعه آن در محيط است و مستقل از متن نميتوان تعريفي از آن داشت.
Concept
philosophical problems arise when language is forced from its proper home into a metaphysical environment, where all the familiar and necessary landmarks and contextual clues are removed.
metaphysical environment as like being on frictionless ice: where the conditions are apparently perfect for a philosophically and logically perfect language, all philosophical problems can be solved without the muddying effects of everyday contexts; but where, precisely because of the lack of friction, language can in fact do no work at all.[158] Wittgenstein argues that philosophers must leave the frictionless ice and return to the "rough ground" of ordinary language in use. Much of the Investigations consists of examples of how the first false steps can be avoided, so that philosophical problems are dissolved, rather than solved: "the clarity we are aiming at is indeed complete clarity. But this simply means that the philosophical problems should completely disappear
See that, See as!
Class Duck-Rabbit: Duck: Rabbit{…}
Duck-Rabbit a = new Duck-Rabbit();
Duck d = (Duck) a;
Rabbit r = (Rabbit) a;
This is wrong. Duck-Rabbit does not exists, So, cannot play 2 simultaneous role!
real meaning of any language phrase is derived from its usage, where the usage is in fact the collection of circumstances under which the phrase/clause was stated.
the meaning by usage: suggests to stop referring to the word (or concept, or object) as the ultimate carrier of meaning
Instead start to see each word
1- as a group of meaning elements, where each of which has a slightly different meaning family resemblance
2- the correct family member is selected according to the current language game.
It means that the essence of an object is no longer ultimately residing within the object itself, but it might as well be found in its usages
Ride:
Ride a bicycle, Horse, Family Resemblance
Water:
Water! دارم خفه ميشم
Water! مواظب باش Discourse: Language Game
Hammer: حتي ماشين
استقلال پرسپوليس را در هم کوبيد! Esteghlal hammered Persepolis 6-0!
با من بازي نکن.
با من بازي نکن!
Cow.Milk()
Milk(Cow)
Using or Calling?
Ali.Save()
Save(Ali)
Ali.Love(Maryam)
Love(Ali, Maryam):
Love(Ali, Maryam, Paternity)
Freeze(object);
Prototype theory is a mode of graded categorization in cognitive science, where some members of a category are more central than others. For example, when asked to give an example of the concept furniture, chair is more frequently cited than, say, stool.
prototype theory was a radical departure from traditional necessary and sufficient conditions as in Aristotelian logic, which led to set-theoretic approaches of extensional or intensional semantics. Thus instead of a definition based model - e.g. a bird may be defined as elements with the features [+feathers], [+beak] and [+ability to fly], prototype theory would consider a category like bird as consisting of different elements which have unequal status - e.g. a robin is more prototypical of a bird than, say a penguin.
تعريف افلاطوني مرد : انساني که مقدار مشخصه جنسيت آن برابر با «مذکر» است!
تعريف ارسطويي مرد: مرد نوعي انسان است که مشخصه هاي جديد و رفتار هاي جديد (مردانگي!!)دارد!
تعريف ويتگنشتايني مرد: همه مردان اين فاميلي، هر يک به ميزان شباهتشان عضو گروهند، نماينده آن ها پورياي ولي!
مرد: توسط همه اشيائي که شباهت به اين اعضاي اين گروه دارند تعريف ميشود، براي اختصار نماينده آنها: پورياي ولي!
مبلمان چيست: صندلي!
صندلي چيست: اين رو بهش صندلي ميگن!
به هيچ عنوان دنبال تعريف مشخصه ها ورفتار براي يک نوع نيست، زيرا يک شي از يک نگرش شبيه کم به يک گروه و از يک نگرش شبيه بسيار به گروهي ديگر است.
Instance-Based Learning
Prototype-based programming
style of object-oriented programming
behaviour reuse (known as inheritance) is performed cloning existing objects that serve as prototypes.
prototypal, prototype-oriented, classless, or instance-based programming.
The first prototype-oriented programming language was Self developed by David Ungar and Randall Smith in the mid-1980s
NO CLASS What could be more object oriented than that?
Object Creation:
from nothing(ex nihilo)
from cloning other Objects may have explicit Link (Delegation/resemblance) Value Inheritance
Cloning Value Inheritance
Prototype programming
- delegation-based JavaScript
- concatenative prototyping
Structure of Explanation
1. Purpose and Motivation
2. Philosophical Background
3. Current Philosophy-Based Pattern
4. Suggested Philosophy-Based Pattern
5. Implementation Example
History Pattern
Purpose
The purpose of this design pattern is to provide a way to manage the changes in object properties through time.
Motivation
Philosophical Background
When we talk about an objects history, the most profound issues of metaphysics
investigates principles of reality
the essence of identity
the question of object continuity.
is it the substance that contains in some way the identity of the object?
is it possible that an object would change its identity as a result of changes in its components?
Example: The Ship of Theseus riddle : Theseus ‘s Paradox
Theseus returned from Crete to Athens after overcoming the Minotaur. The people of Athens have kept this ship for a long time, and from time to time they have replaced the old, rotten logs with new and strong ones. At some point, there was not a single original log that was left in the ship. The question that arose was whether if after all those changes, we are still looking at the ship in which Theseus sailed.
For, if we would refer to the ship at two different time points, we would discover that we are referring to two entities made up of different matter. But still, it seems that intuitively, we identify those two different entities as one – The ship of Theseus. So how can we resolve this contradiction between our intuition (a single object), and the plain facts (two different entities)?
Leibnitz: philosopher and mathematician of the 17th and 18th centuries
Principle of the Identity of Indiscernibles (also known as the Criterion of Identity or Indiscernibility Principle).
identity brings about indiscernibility of properties. That is, if object A is identical to object B, then every property of A will be identical to the same property of B, and therefore if two objects are (not) differentiable in any property, even in the property of their location in space, then they are (not) different from each other.
the table located in this room is not identical to the table in the other room (differentiated in at least one property their location in space).
the table in this room and the table I like most (they are two objects with identical properties and therefore they are one).
at two different time points, are identical?
cup example
hold in my hand a cup with a handle, and suddenly, the handle, which might have been loose already, falls off. Now I am holding a cup without a handle.
Are we talking about the same cup? Are the cup before the loss of the handle and the cup after the loss the same?
Intuitively we would assume that indeed they are. according to Leibnitz Identity Principle, these are different cups, since they are differentiated in at least one property (the existence of the handle).