当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture07 OBJECT ORIENTED DEVELOPMENT Class and Object

资源类别:文库,文档格式:PDF,文档页数:90,文件大小:714.37KB,团购合买
点击下载完整版文档(PDF)

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Computational Thinking and Approach Lecture 7 Dr.Jialiang LU Jialiang.lu@situ.edu.cn

Computational Thinking and Approach Lecture 7 Dr. Jialiang LU Jialiang.lu@sjtu.edu.cn

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Class and Object OBJECT ORIENTED DEVELOPMENT

OBJECT ORIENTED DEVELOPMENT Class and Object

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Review of Objects Using objects is a techniques for structuring the data that our programs use. o So far,our programs have made use of objects created from pre-defined class such as circle. An object was defined as an active data type that knows stuff and can do stuff. More precisely,an object consists of: 1.A collection of related information. 2.A set of operations to manipulate that information. 3

Review of Objects • Using objects is a techniques for structuring the data that our programs use. • So far, our programs have made use of objects created from pre-defined class such as Circle. • An object was defined as an active data type that knows stuff and can do stuff. • More precisely, an object consists of: 1. A collection of related information. 2. A set of operations to manipulate that information. 3

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Review of Objects The information is stored inside the object in instance variables. The operations,called methods,are functions that "live"inside the object. Collectively,the instance variables and methods are called the attributes of an object. 4

Review of Objects • The information is stored inside the object in instance variables. • The operations, called methods, are functions that “live” inside the object. • Collectively, the instance variables and methods are called the attributes of an object. 4

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Circle A circle object will have instance variables such as center,which remembers the center point of the circle,and radius,which stores the length of the circle's radius. The draw method examines the center and radius to decide which pixels in a window should be colored. 5

Circle • A Circle object will have instance variables such as center, which remembers the center point of the circle, and radius, which stores the length of the circle’s radius. • The draw method examines the center and radius to decide which pixels in a window should be colored. 5

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Circle The move method will change the value of center to reflect the new position of the circle. All objects are said to be an instance of some class.The class of an object determines which attributes the object will have. A class is a description of what its instances will know and do. 6

Circle • The move method will change the value of center to reflect the new position of the circle. • All objects are said to be an instance of some class. The class of an object determines which attributes the object will have. • A class is a description of what its instances will know and do. 6

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Circle New objects are created from a class by invoking a constructor.You can think of the class itself as a sort of factory for stamping out new instances. 。( Consider making a new circle object: mycircle Circle(Point (0,0),20) circle,the name of the class,is used to invoke the constructor. 7

Circle • New objects are created from a class by invoking a constructor. You can think of the class itself as a sort of factory for stamping out new instances. • Consider making a new circle object: myCircle = Circle(Point(0,0),20) • Circle, the name of the class, is used to invoke the constructor. 7

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Circle myCircle Circle(Point(0,0),20) This statement creates a new circle instance and stores a reference to it in the variable mycircle. The parameters to the constructor are used to initialize some of the instance variables (center and radius)inside mycircle. 8

Circle myCircle = Circle(Point(0,0), 20) • This statement creates a new Circle instance and stores a reference to it in the variable myCircle. • The parameters to the constructor are used to initialize some of the instance variables (center and radius) inside myCircle. 8

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Circle myCircle Circle(Point (0,0),20) Once the instance has been created,it can be manipulated by calling on its methods: myCircle.draw(win) mycircle.move (dx,dy) 9

Circle myCircle = Circle(Point(0,0), 20) • Once the instance has been created, it can be manipulated by calling on its methods: myCircle.draw(win) myCircle.move(dx,dy) 9

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Class e Classes are just a way to define new sorts of stuff. - Classes are templates for creating user- defined objects. -Instances represent the concrete items in a program's domain. Classes serve as instance factories. 10

Class • Classes are just a way to define new sorts of stuff. – Classes are templates for creating user￾defined objects. – Instances represent the concrete items in a program's domain. – Classes serve as instance factories. 10

点击下载完整版文档(PDF)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共90页,可试读20页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有