上游充通大 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 userdefined objects. – Instances represent the concrete items in a program's domain. – Classes serve as instance factories. 10