750 likes | 924 Views
Model-Driven Programming Education. Workshop @ ACE 2013. Michael E. Caspersen Department of Computer Science and Centre for Science Education Aarhus University, Denmark mec@cse.au.dk. Three Perspectives on Programming. Instructing the computer (coding)
E N D
Model-DrivenProgramming Education Workshop @ ACE 2013 Michael E. Caspersen Department of Computer Science and Centre for Science Education Aarhus University, Denmark mec@cse.au.dk
Three Perspectives on Programming • Instructing the computer (coding) • the purpose of programming is to instruct the computer • focus is on aspects of program execution such as storage layout, control flow, parameter passing, etc. • Managing the program description • the purpose of programming is to create a software architecture that provides overview and understanding of the entire program • focus is on aspects such as visibility, scope, encapsulation, modularity, software design etc. • Conceptual modeling • the purpose of programming is to express concepts, structure and relations • focus is on constructs for describing concepts, phenomena and relations between these Model-Driven Programming Education
Characterization and Expectations • Characterise the introductory programming course at your home institution • other views on programming? • how are the views balanced in the intro course? • what defines the progression in your intro course? • What are your expectations for this workshop? Model-Driven Programming Education
Contents and Progression • Traditional approach • typical textbooks only address the first and to some extend the second perspective • topics are organized according to the syntactical structures in the programming language (bottom-up) • tendency to completeness in coverage of topics • syntax-driven progression • Our approach • a balanced coverage of all three views • conceptual modeling is leading the way • systematic programming (no more pulling rabbits out of the hat) • early bird & spiral approach • model-driven progression Model-Driven Programming Education
Track String artist String songName int min int sec String toString() Driver void exam() Sample ExamAssignment • Create a simple classTrack ... with constructor and a toStringmethod… • Create a test methodexam… • Create twoinstancies… • Create a new classPlaylist ... • Implement the methodsaddTrack and removeTrack • Modify the test method to create a Playlistobject… • Implementand test methodfindShortestTrack • Implement and test methodfindTracksByArtist … • Let the Trackclassimplementinterface Comparable… • Implement the methodprintSortedTracksand modify ... * Playlist StringplaylistName voidaddTrack(Track t) voidremoveTrack(Track t) TrackfindShortestTrack() List<Track> find(String s) voidprintSortedTracks() Model-Driven Programming Education
Track String artist String songName int min int sec String toString() Comparable intcompareTo(T e) Collections void sort(List l) Driver void exam() The ”Complete” Model Java’s Collections Framework <<implements>> Playlist StringplaylistName voidaddTrack(Track t) voidremoveTrack(Track t) TrackfindShortestTrack() List<Track> find(String s) voidprintSortedTracks() * Model-Driven Programming Education
Oral Exam Written Exam Multiple Choice Practical Exam Learning Goals and Examination Form Alignment • By the end of the course the students must be able to • apply fundamental constructs in an ordinary PL • explain the architecture of simple programs • explain the semantics of simple specification models • implement simple specification models in an ordinary PL • apply selected classes from a standard class library • Weekly mandatory assignments prepare the students for the exam • but don’t count in the final grading Model-Driven Programming Education
An Academic Year A Quarter (7 weeks) 1 Q1 2 Q2 3 Q3 4 Q4 5 6 7 Course Context and Structure Progression Complexity of class models (language stuff added by need) Model-Driven Programming Education
Course Phases (week numbers) (1) Getting started Overview of fundamental concepts. Learning the IDEs and other tools. (2) Introduction to the basics Class, object, state, behaviour, control structures. (3-4) Conceptual framework and structural patterns Control structures, data structures (collections), class relationship, patterns for implementing structure (association). (4-5) Programming method STREAM, patterns for implementing functionality (algorithmic patterns). (6) Subject specific assignment Practice on harder problems. (7 (+ 8-9)) Practice Achieve routine in solving standard tasks (prep for exam). Model-Driven Programming Education
Key Points (and Agenda) • Conceptual modelling • Conceptual modelling is the defining characteristic of OO • Progression • Progression in terms of complexity of class models (not syntax of a programming language) • Systematic programming • Systematic programming revealed through basic (structural and algorithmic) patterns and STREAM (a programming method for novices) • Learning-theoretic foundation • A learning-theoretic foundation (Cognitive Load Theory, Cognitive Apprenticeship, and Worked Examples) Model-Driven Programming Education
References • O.L. Madsen, B. Møller-Pedersen and K. Nygaard (1993): Object-Oriented Programming in the BETA Programming Language, Addison-Wesley. [ Link ] • M.E. Caspersen (2007), Educating Novices in the Skills of Programming, DAIMI PhD Dissertation PD-07-4, ISSN 1602-0448 (paper), 1602-0456 (online). [ Link] • M.E. Caspersen and J.B. Bennedsen (2007), Instructional Design of a Programming Course: A Learning-Theoretic Approach, Proceedings of the 3rd International Computing Education Research Workshop, ICER 2007, Atlanta, GA, USA, September 2007, pp. 111-122. [ Link] • J.B. Bennedsen and M.E. Caspersen (2007), Assessing Process and Product — A Practical Lab Exam for an Introductory Programming Course, Innovation in Teaching and Learning in Information and Computer Sciences, Vol. 6 (4), Special Issue on Innovative Methods of Teaching Programming, pp. 183-202. [ Link] • J.B. Bennedsen, M.E. Caspersen and M. Kölling (2008), Reflections on the Teaching of Programming, Lecture Notes in Computer Science, Vol. 4821, Springer-Verlag. [ Link, ToC] • J. B. Bennedsen and M.E. Caspersen (2008), Model-Driven Programming, in [5], pp. 116-129. [ Link] • M.E. Caspersen and M. Kölling (2009), STREAM: A First Programming Process, ACM Transactions on Computing Education (TOCE), Vol. 9 (1), Article No. 4, pp. 1-29. [ Link] Model-Driven Programming Education
A Conceptual Framework forObject-Oriented Programming There is more to OO than Java...
Kristen Nygaard on Object-Orientation A program execution is regarded as a physical model system simulating the behavior of either a real or imaginary part of the world. Physical modeling is based upon the conception of reality in terms of phe-nomena and concepts. A physical model system is construc-ted, modelingphenomena by objects and concepts by categories of objects. Kristen Nygaard, 1926-2002 Model-Driven Programming Education
An Interlude on Concepts What is a concept? Model-Driven Programming Education
Concepts and phenomenons of EPR • Electronic Patient Record (EPR) • Patient (Lance Armstrong, John Kerry, ...) • Treatment (bandaging, rest, physical therapy, ...) • Diagnosis (sprained wrist, broken leg, yellow fever, ...) • Operation (removing the appendix, sterilization, brain surgery, ...) • Doctor (Beth Barry, Lou Lazanta, ...) • Nurse (Jane Clemenza, Laura Hopcroft, ...) Model-Driven Programming Education
Model of EPR * Patient Diagnosis * 1 * Doctor Treatment ... Senior Doctor Junior Doctor Problem domain Model Model-Driven Programming Education
Problem/vision concerning phenomena Conceptual Modelling modelling Conceptual model (problem-specific concepts) Specification model (realised concepts) abstraction abstraction Objects (program, language, OS, machine) Problem domain Model Model-Driven Programming Education
Phenomena and Concepts • A phenomenon is • a thing that has definite, individual existence in reality or in the mind; anything real in itself • A concept is • a generalised idea of a collection of phenomena, based on knowledge of common properties of instances in the collection Model-Driven Programming Education
Characterisation of Concepts • Designation • The collection of names (or pictures) by which the concept is known • Extension • The collection of phenomena that the concept somehow covers • Intension • The collection of properties that in some way characterize the phenomena in the extension of the concept Model-Driven Programming Education
Examples of Concepts Designation Extension Intension Horse Car Rectangle Food Model-Driven Programming Education
Aristotelian View • Characterisation (intension :-) • The intension is a collection of properties that may be divided into two groups • defining properties that all phenomena in the extension must have • characteristic properties that the phenomena may have • Well-defined concepts with sharp borders • Relatively homogeneous phenomena • The extension is uniquely determined by the intension (objectively determinable) • Examples (extension :-) • Does to some extend exist in well-established topic areas such as mathematics, physics, zoology, botany, ... Model-Driven Programming Education
Prototypical View • Characterisation (intension :-) • The intension of a concept consists of examples of properties that phenomena may have, together with a collection of typical phenomena covered by the concept: prototypes • Blurry concepts with vague borders • Great variation among phenomena • The extension is not uniquely determined by the intension • Examples (extension :-) • Everywhere! Model-Driven Programming Education
PSC RC Problem domain Model Conceptual Modelling, revisited • Problem Specific Concepts (PSC) are almost always of prototypical nature • Realised Concepts (RC) are Aristotelian (because of our programming languages) • This mismatch represents a challenge for modelling • to give an Aristotelian definition to prototypical concepts Model-Driven Programming Education
Identification of phenomena Socrates Batmobile Hannibal’s march across the Alps Neil Young Sirius 2000 Herbie Hillary Clinton Classification Person Car Neil Socrates Hillary Batmobile Herbie Journey Sirius 2000 Hannibal’s march across the Alps Concept Formation Model-Driven Programming Education
Class Objects Person : Person ”Bruce” 63 String name int age : Person ”Paul” 70 : Person ”Michael” 52 isTeenager() isOld() age() Classification in UML Classes represent concepts, objects represent phenomena Example Concept: Person Phenomena: Bruce, Paul, Michael Model-Driven Programming Education
Classification in Java class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } public void birthday() { age++; } public isTeenager() { return (age >= 13 && age <= 19) } } List l = new ArrayList(); l.add( new Person(”Bruce”, 63) ); l.add( new Person(”Paul”, 70) ); l.add( new Person(”Michael”, 52) ); Model-Driven Programming Education
Relations between concepts • Aggregation • has-a • Association • X-a • Generalization/specialization • is-a Organization of knowledge... Model-Driven Programming Education
Aggregation (has-a) Car Relation between concepts describing a whole and (some of) the parts which constitutes the whole (part-whole structure). UML: Composition Motor Wheel Body Seat Door Roof Fender Journey Duration Departure Means of transportation Destination Model-Driven Programming Education
Aggregation in UML (1) ClockDisplay NumberDisplay hours; NumberDisplay minutes; String displayString; timeTick() setTime(int h, int m) getTime(): String Model-Driven Programming Education
Aggregering i UML (2) NumberDisplay ClockDisplay int limit; int value; String displayString; 2 getValue() getDisplayValue() setValue() increment() timeTick() setTime(int h, int m) getTime(): String Model-Driven Programming Education
Aggregation in Java class NumberDisplay { private int limit, value; public NumberDisplay() { ... } public int getValue() { ... } public String getDisplayValue() { ... } public void setValue(int replacementValue) { ... } public void increment() { ... } } class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; private String displayString; public ClockDisplay() { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); } public void timeTick() { ... } public void setTime(int hour, int minutes) { ... } public String getTime() { ... } } Model-Driven Programming Education
Association (X-a) Relation that describes a dynamic relation between concepts where the phenomena exist independently of each other and just occasionally are associated. MailServerkeepsMailItem Person owns Car Person rents Car Person loves Person Person is-friend-with Person Student is-enrolled-at Course Patient have-had Disease Model-Driven Programming Education
Association in UML * keeps MailServer MailItem owns * Person Car 0..1 owned can-drive * takes Student Course * * Multiplicity (cardinality): 0..1, 1, n, a..b, 0..* (*) Role Orientation (1-way, 2-way) Model-Driven Programming Education
Association in UML (X-a) X = keeps MailItem MailServer from: String to: String message: String 0..* howManyMessages(String who): int getNextMailItem(String who): MailItem post(MailItem item) getFrom(): String getTo(): String getMessage(): String print() Model-Driven Programming Education
Association in Java classMailServer { private List messages; public MailServer() { messages = new ArrayList(); } public int howManyMessages (Stringwho) { ... } public MailItem getNextMailItem (Stringwho) { ... } public void post(MailItem item) { ... } } class MailItem { private String to; private String from; private String message; public MailItem( ... ) { ... } public String getFrom() { ... } public String getTo () { ... } public String getMessage() { ... } public void print() { ... } } Model-Driven Programming Education
Generalization/specialization (is-a) Combine concepts to a more general concept. Vehicle Car Truck Bus Taxi Passenger car Ambulance Van Sedan Model-Driven Programming Education
What makes a concept special? Means of transportation Plane Passenger plane Airliner Sports plane Military plane Ship Vehicle Car Bus Truck Lorry Pick-up Truck Passenger car Van Taxi Bicycle Figure Ellipse Circle Triangle Isosceles triangle Equilateral Right-angled Four-sided polygon Trapezoid Parallelogram Rectangle Square Kite Additional properties! Model-Driven Programming Education
B is-a A Intension(A) Intension(B) A B Extension(B) Extension(A) Specialization: extra properties A concept’s intension: The collection of properties characterising the concept A concept’sextension: The collection of phenomena covered by the concept Model-Driven Programming Education
Specialization in UML LendableItem General concept Special concepts lend(l: borrower) return() isAvalable() Book Video author() publisher() ISBN() producer() format() playingTime() Model-Driven Programming Education
Specialization in Java class Book extends LendableItem { String author() { ... } String puclisher() { ... } String ISBN() { ... } ... } class Video extends LendableItem { String producer() { ... } String format() { ... } int playingTime() { ... } ... } class LendableItem { void lend(Borrower b) { // code for lend } void return() { // code for return } boolean isAvalable() { // code for isAvalable } ... } Model-Driven Programming Education
Classification Aggregation has-a Association X-a Specialization is-a class Reference (attribute) aggregate has responsibility for the creation Reference (attribute) dynamic relation extends subtype Concept formation and OO-languages Model-Driven Programming Education
Summary • Conceptual framework for object-orientation • Concepts and modelling • Structure: aggregation, association, specialization • is used for organizing knowledge about a problem domain and structure in the solution domain • Is (to some extend) supported by language constructs in OO languages • Modelling examples • Abstract models in UML • Implementation in Java • Examples from textbook [Barnes & Kölling] – which does not explicitly present the models... Model-Driven Programming Education
Model-Driven Programming Programming in Context
Hand-in-Hand Modeling and Coding (1) • David Gries (Edsger W. Dijkstra) • the loop body and the loop invariant is developed hand-in-hand with the latter leading the way • We (Kristen Nygaard) • coding and class modeling is done hand-in-hand with the latter leading the way • Design by contract and systematic programming • a class model is a design contract in precisely the same way as a loop invariant is • code is introduced on purpose (fulfilling the contract) Model-Driven Programming Education
Intermezzo: Contracts at Four Levels • Model • relations between classes (interfaces) • association, aggregation/copmposition, specialization • Interface (spec) • functional specification (pre and post conditions) • Class (impl) • class invariant (representation invariant) • Method • assertions (loop invariant) • Systematic programming • systematic techniques associated with each level Model-Driven Programming Education
Systematic Implementation Techniques • Inter-class structure • implementation of specification model using standard patterns for implementing relations between classes • Intra-class structure • implementation of interface or class specifications using STREAM • implementation using class invariants • Methods • algorithmic patterns (sweep, search, divide and conquer, ...) • loop invariant techniques Separation of concerns... Model-Driven Programming Education
Intermezzo: Contracts at Four Levels • Model • relations between classes (interfaces) • association, aggregation/copmposition, specialization • Interface (spec) • functional specification (pre and post conditions) • Class (impl) • class invariant (representation invariant) • Method • assertions (loop invariant) • Systematic programming • systematic techniques associated with each level Our focus today Model-Driven Programming Education
Hand-in-Hand Modeling and Coding (2) Person name ... Model-Driven Programming Education
Hand-in-Hand Modeling and Coding (2) class Person { private String name; public Person(String name) { this.name = name; } ... } Person name ... Model-Driven Programming Education
Hand-in-Hand Modeling and Coding (2) class Person { private String name; public Person(String name) { this.name = name; } ... } lover 0..1 Person Model-Driven Programming Education