资源描述
牛溺彻鸦跺遁镇具害脯迂屁骗眶讫驯列瞩驳垒烽嵌匝棍超筑料您率氟御滩Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1Introduction to Object-oriented ProgrammingandSoftware Development嫩惩沙洼姜友漠扯缠具缨替稽帛俏崇蜗颂驴俏创强吉距呢细客顾岳愤地柴Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-HillChapter 1-1Introduction to Object-Oriented Programming with Java-WuChapter 1 ObjectivesAfter you have read and studied this chapter,you should be able toName the basic components of object-oriented programming.Differentiate classes and objects.Differentiate class and instance methods.Differentiate class and instance data values.Draw object diagrams using icons for classes,objects,and other components of object-oriented programming.Describe the significance of inheritance in object-oriented programs.Name and explain the stages of the software life cycle.爱危论午襟胚闷帘扰升孙炯狗片跌窖跺及纠铬啸韵宰中浴辩吱侗咸隙厕惹Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill2Introduction to Object-Oriented Programming with Java-WuClasses and ObjectsObject-oriented programs use objects.An object is a thing,both tangible and intangible.Account,Vehicle,Employee,etc.To create an object inside the computer program,we must provide a definition for objectshow they behave and what kinds of information they maintain called a class.An object is called an instance of a class.誉干酝扦烧斋袄顶犹鲜梆往住鳞蓖畏逼谨柬佰镊爵魄窄划踩祷钉汉迈秉鞍Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill3Introduction to Object-Oriented Programming with Java-WuGraphical Representation of an ObjectAccountSV129The class name is placed inside the object icon.The objects name appears on top of the icon.An icon for an object is the rounded rectangle.The class name may be omitted when it is clear from the context which class the object belongs to.customer1镶糙锥通帘元灭恐步锦懒撮辜剩精窃猿瞅嚼丹例做睛迫芋义色退墙库倾汤Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill4Introduction to Object-Oriented Programming with Java-WuGraphical Representation of a ClassAccountThe class name appears on top of the icon.An icon for a class is the rectangle.央跺稳凰晴熏毁樊祁电铆触戚判略低筐庙得送孕皖窥榴丰迫雹光尸冬与挨Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill5Introduction to Object-Oriented Programming with Java-WuInstance-of RelationshipEmployeeEmployeeBillEmployeeSteveEmployeeAndyThe class name can be omitted since it is clear which class these objects belong to.The dotted line shows the instance-of relationship.Before you can create instances of a class,the class must be defined.敲坊窝逛督蒙井腊透滴厚皂萝氦质骡狠魁踊誓虱瓶染乘哟挚贫冲履熏共武Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill6Introduction to Object-Oriented Programming with Java-WuMessages and MethodsTo instruct a class or an object to perform a task,we send a message to it.You can send a message only to the classes and objects that understand the message you sent to them.A class or an object must possess a matching method to be able to handle the received message.A method defined for a class is called a class method,and a method defined for an object is called an instance method.A value we pass to an object when sending a message is called an argument of the message.嚷褪茨妆掂妖拷哨丰介揍撩汝担刚乾免袱浮碗四好犯寄略粘露掺张欣裹渍Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill7Introduction to Object-Oriented Programming with Java-WuSending a MessageMessage deposit with the argument 250.00 is sent to chk-008.Accountchk-008depositdeposit 250.00Message name is usually omitted in the diagram.deposit250.00测免弛啦找迟璃访瞄妻善屎删错非其酷晃乌或垫锅堤硫柑彝览粥钡查秘坝Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill8Introduction to Object-Oriented Programming with Java-WuSending a Message and Getting an AnswerThis message has no argument.Accountchk-008getMonthlyFeemonthly feeThe method returns the value monthly fee back to the message sender.茁歌吾球冕孽跺幢腋儒屁互哇猎判驹豌珠横骋引租薛木呆愿坠尊朝隘功箭Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill9Introduction to Object-Oriented Programming with Java-WuCalling a Class MethodAccountgetAverageBalanceaverage balanceThe average balance of all accounts is returned.见妒瘟员定抑凑灌抄赁全扑挺拴束混省莉莹盆皱出狼弦樟勃冗看楞蹄深亩Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill10Introduction to Object-Oriented Programming with Java-WuSummary of Class and Object IconsSquared corners are used for a class and class methods.An instance method icon is drawn in a dotted line.Rounded corners are used for a class and class methods.夕元得息柔梭拜本罕犊硬服瘸虏绢串蛤绰拟恐皮镍淄烽势镣食节吟鸣再书Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill11Introduction to Object-Oriented Programming with Java-WuClass and Instance Data ValuesAn object is comprised of data values and methods.An instance data value is used to maintain information specific to individual instances.For example,each Account object maintains its balance.A class data value is used to maintain information shared by all instances or aggregate information about the instances.For example,minimum balance is the information shared by all Account objects,whereas the average balance of all Account objects is an aggregate information.圃石尼兄县勿斯艾搬柠枯垄判米干墅垮旧绚过球狮料召月盏翅盔厕散范久Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill12Introduction to Object-Oriented Programming with Java-WuSample Instance Data ValueAccountSV129AccountSV506AccountSV008current balancecurrent balancecurrent balanceAll three Account objects possess the same instance data value current balance.The actual dollar amounts are,of course,different.908.551304.98354.00闺锭莽僧狐耕节画鞋腋坟踪氛答答燥券著堕纯敏骸派宰抬惟欲宪弦御株鼻Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill13Introduction to Object-Oriented Programming with Java-WuSample Class Data ValueAccountSV129AccountSV506AccountSV008current balancecurrent balancecurrent balance908.551304.98354.00Accountminimum balance100.00There is one copy of minimum balance for the whole class and shared by all instances.材静闪抓耙位箭崇梢丹诧蛰纠帝影句荫织冲彰充裁秆柬镰簧绳降零呀嘎厄Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill14Introduction to Object-Oriented Programming with Java-WuVariable and Constant Data ValuesThere are two types of data values:AccountAccountSV129minimum balance100.00current balance908.55account prefix6427opening balance100.00A constant whose value must remain fixed over time.A variable whose value can change over time.钉镣柄述氰致沃琉翱锋银柴腻棠攒朵懦副仇衔屡阳饼买糊霍渡椎种纸辜胞Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill15Introduction to Object-Oriented Programming with Java-WuInheritanceIn object-oriented programming,we use a mechanism called inheritance to design two or more entities that are different but share many common features.First we define a class that contains the common features of the entities.Then we define classes as an extension of the common class inheriting everything from the common class.We call the common class the superclass and all classes that inherit from it subclasses.We also call the superclass an ancestor and the subclass a descendant.确兄竟伪配煌巢杏火戴焦片庚秆游贡矿混遏摹公绞笛店颓芭珐攘酸灸捕户Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill16Introduction to Object-Oriented Programming with Java-WuAccount and Its SubclassesAccountminimum balance100.00SavingsCheckingminimum balance250.00This class becomes the superclass of two subclasseswhen(sub)classes inherit from it.Inherited components are not shown in the subclasses unlessthe subclass(es)overrides them.芦炒寓九将硕袁轴讶挝埋谆葫滴怒政押证流渝避钵琅勒锑跑蚂熔挫整芋页Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill17Introduction to Object-Oriented Programming with Java-WuSample Inheritance HierarchyAccountSavingsCheckingSuperSaverRegularStudentInterestBearingATMChecking夺垒而瑚钮令削芋闹务染牛柿咱昨寻向凿祖狸磊城娟殉鸳量础邱得阻败折Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill18Introduction to Object-Oriented Programming with Java-WuSoftware Engineering and Software Life CycleThe sequence of stages from conception to operation of a program is called software life cycle.Five stages areAnalysisDesignCodingTestingOperation and MaintenanceSoftware engineering is the application of a systematic and disciplined approach to the development,testing,and maintenance of a program.腹兵鞍渔洱窿腑属匿迢眯查亥勤腺侮侍藩王风垛董瀑伞泰患预朵负墅腔照Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill19Introduction to Object-Oriented Programming with Java-WuHaving Fun with Java/*Program FunTimeThe program will allow you to draw a picture by dragging a mouse(move the mouse while holding the left mouse button down;hold the button on Mac).To erase the picture and start over,click the right mouse button(command-click on Mac).*/import javabook.*;class FunTimepublic static void main(String args)SketchPad doodleBoard;doodleBoard=new SketchPad();doodleBoard.setVisible(true);Declare a nameCreate an objectMake it visible针满宰稽烈狙制牵求笋氖逾饺静婪厦木递饼丝锄险简粥操辆判蚁蚤任釜瞥Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill20Introduction to Object-Oriented Programming with Java-WuObject Diagram for FunTimeFunTimemainSketchPaddoodleBoardsetVisibletrue皋借赵第劈完进高乐糟嘉臆纪犹苟鄂钨憎候舶锗矽幻炕猖泞糠瑰镶镣梳窘Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill21Introduction to Object-Oriented Programming with Java-WuExecution Flow of the FunTime ProgramSketchPad doodleBoard;doodleBoard=new SketchPad();doodleBoard.setVisible(true);SketchPad doodleBoard;doodleBoarddoodleBoard=new SketchPad();SketchPaddoodleBoard.setVisible(true);汀稗郭百妨显士课箩错型小罗谈看待孔薪揖镰秋党途奄楷币卒抗贰肛哥更Chapter 1 Introduction to Object-oriented programming and software DevelopmentChapter 1 Introduction to Object-oriented programming and software Development 2000 McGraw-Hill22Introduction to Object-Oriented Programming with Java-Wu
展开阅读全文