Forth Stack Programming LanguageSlide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Study on Object-Oriented Language EiffelAnurag Katiyar Jie YaoInstructor: Dr. Christian CollbergApril 30th, 2008IntroductionHistoryBertrand MeyerCase StudySpecial PropertiesMultiple inheritance and RenamingSpecial PropertiesTyping (Static)GenericityUnconstrained STACK[G]constrainedBINARY_TREE[G->COMPARABLE]Assignment attemptX ?= YAnchored declarationsX: like YNo type castSpecial Properties Exception Handling No Main and GlobalsRoot classRoot procedureDesign Principles Design by Contract Command Query Separation Uniform Access Principlea.balance (attribute? function?)Internals Compilation process Garbage CollectionMark and SweepGeneration ScavengingOO languages ComparisonSummaryObjective-CIntroduction[Karthik Ravichandra][Bhavin Mankad]CS520: Introduction to Objective-C2History Designed by Brad Cox and Tom Love at their company StepStone Steve Jobs’ NeXT licensed Objective C from StepStoneand released their own version of Objective-C compiler, libraries (NeXTstep) NeXT partnered with Sun Microsystems to develop OpenStep based on NeXTstep GNUstep - Glatting, Stallman Apple acquired NeXT and used OpenStep in Mac OS-X1984198819921996* Timeline not to scaleCS520: Introduction to Objective-C3Goals of Design Object Oriented Design and Development Strict Super-set of C Simple Syntax Extensions to C, influenced by SmallTalk Convenient Mixing of Structured and Object Oriented Programming Dynamic BehaviorCS520: Introduction to Objective-C4Sample Code Square.h - Interface#import “Shape.h”@interface Square: Shape {float side;}+ (void) countRectangles;- (id ) initWithSide: (float) side;@end; Square.m - Implementation#import “Square.h”@Implementation Square-(void) initWithSide: (float) side{//method body}@endCS520: Introduction to Objective-C5Objects, Classes and Inheritance Basic Building Blocks of OO programming Only Single Inheritance allowed NSObject is the root for all classes Dynamic or Static Typing for Objectsid square =[ [Square alloc] init];orSquare *square = [[Square alloc] init];CS520: Introduction to Objective-C6Messaging Syntax: Method calls via message passing Preprocessor translates a message into objc_msgSend(..) function Class template lookup for method calls on objects at runtime (Similar to Luca!)[ rectangle init];[ rectangle setLength:100 andWIdth:60]; Message without arguments Message with two argumentsCS520: Introduction to Objective-C7Dynamic Behavior Dynamic Typing Deciding the class of an object at runtime. Dynamic Binding Deciding which method to invoke at runtime.id Obj = getReceiverObj(bool flag); // True – Rectangle, False – SquareSEL msg = getMessage(bool flag); // True – SetWidth, False - Setsize[ Obj performSelector: msg];CS520: Introduction to Objective-C8Categories Extends the functionality of a class. A good alternative to sub-classing. Sub-classes inherit the new methods. Merits Can split implementation of a huge class. Simplifies code management. Base class code is not recompiled.CS520: Introduction to Objective-C9Properties. Allows for easier ways to access variables. Can associate attributes. readwrite, readonly etc. Can synthesize getter and setter methods.@interface Rectange{…@property (readwrite) int size;…}@implementation Rectangle{…@synthesize size;…}Rectangle *rect = [[Rectangle alloc] int];rect.size = 10; // [Rectangle setSize: 10]CS520: Introduction to Objective-C10Memory Management Manual Memory Management in 1.0 Uses reference counting technique. Keywords - retain, release, autorelease. Example:Rectange *rect = [[Rectangle alloc] init]; // retainCount is 1.Rectangle *tmprect = rect; // Another reference to rect.[tmprect retain]; // So we increment the retainCount.….[tmprect release]; // Decrement retainCount.….[rect release];CS520: Introduction to Objective-C11Summary One of the early Object Oriented Languages. Popularized by Apple. Based on C, influenced by Smalltalk. Significant Dynamic Behavior. Some cool features like Categories, Properties etc. Generation based Garbage Collection.MODULA-3Swaminathan Sankararaman Bojan DurickovicMODULA-3 ExampleMODULE Main;Main.m3:BEGINn := 3;END Main.ImportsExportsLinkedList.i3:INTERFACE LinkedList;PROCEDURE Add(VAR I : INTEGER);BEGINLinkedList.m3END LinkedList.MODULE LinkedList;PROCEDURE Add(VAR I : INTEGER) = ...END LinkedList.IMPORTS LinkedListVAR n : INTEGER;LinkedList.Add(n);HistoryYear Event1986 Proposal1988-1989 Language Definition1990s DEC SRC-M 3, CM3 a nd PM3 released1990s Popular as a teaching language1994 SPIN OS developed1996-1997 CVSup developed2000 Critical Mass Inc. ceases operations2000-2002 Elegosoft takes over CM3 a n d PM3Goals and Target Audience◮Structuring of Large Programs◮Safety and Robustness◮Machine-level programming◮SimplicityTARGET AUDIENCEIntendedActualProgrammers oflarge, sophisticated systemsand applicationsProgramming Language InstructorsResearchersObjects and GenericsOBJECT◮Record paired with Method SuiteTYPE T = OBJECTa: INTEGER;METHODS a() := AEND;PROCEDURE A(self: T) = ... ;GENERICS◮Parametric Polymorphism◮Entire Modules and Interfacesare GenericGENERIC MODULE LinkedList(Elem);REVEAL T = BRANDED OBJECT val: Elem.T ;INTERFACE Integer; TYPE T = INTEGER END Integer.END m1.METHODS set(v: Elem.T) := P; END;PROCEDURE P(self:T; v:Elem.T) = ... ;MODULE IntList = LinkedList(Integer) END IntList.INTERFACE IntList = LinkedList(Integer) END IntList.GENERIC INTERFACE LinkedList(Elem); TYPE T <: REFANY;Type SystemNO Ambiguous Types or Target-TypingVAR x : REAL; y : INTEGER ; z : REAL ;x := y∗ z ;(∗ Type o f y ∗ z de pe nd s on y and zand not x ∗ )NO Auto-ConversionsVAR x : REAL; y : INTEGER ;y := x ;(∗ No Auto mati c f l o o r ( ) .S t a t i c E r r o r ∗)Type Compatibility S <: T =⇒ S ⊆ TStructural Equivalence T ≡ U =⇒Expanded Definitions of T and U are the sameProcedures Global→First-Class,Local→ Second-ClassInformation Hiding - Revelations◮At an implementation level, reveal only features of t he typerelevant to that levelREVEAL T <: U◮Revelations are linearly ordered with final revelation definingthe concrete type of the object2nd1stImplementor knows only
View Full Document