انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة
الكلية كلية تكنولوجيا المعلومات
القسم قسم البرامجيات
المرحلة 2
أستاذ المادة احمد خلفة عبيد العجيلي
09/03/2019 10:24:34
object-oriented programming with java ahmed al-ajeli more on object interaction creating cooperating objects ahmed al-ajeli lecture 5 2 concepts to be covered •overloading •composition •object interaction •internal/external method calls •the debugger object-oriented programming with java ahmed al-ajeli 3 implementation – clockdisplay (1) public class clockdisplay { private numberdisplay hours private numberdisplay minutes private string displaystring // simulates the actual display public clockdisplay() { hours = new numberdisplay(24) minutes = new numberdisplay(60) updatingdisplay() } 4 implementation – clockdisplay (2) public clockdisplay(int hour, int minute) { hours = new numberdisplay(24) minutes = new numberdisplay(60) settime(hour, minute) } public void timetick() { minutes.increment() if(minutes.getvalue() == 0) { // it just rolled over! hours.increment() } updatingdisplay() } object-oriented programming with java ahmed al-ajeli 5 implementation – clockdisplay (3) public void settime(int hour, int minute) { hours.setvalue(hour) minutes.setvalue(minute) updatingdisplay() } public string gettime() { return displaystring } private void updatingdisplay() { displaystring = hours.getdisplayvalue() + ":" + minutes.getdisplayvalue() } } 6 overloading •a class may contain more than one constructor, or more than one method of the same name, as long as each has a distinctive set of parameters. •example: clockdisplay class has two constructors: clockdisplay() clockdisplay(int hour, int minute) object-oriented programming with java ahmed al-ajeli 7 object interaction (1) •two objects interact when one object calls a method on another. •the interaction is usually all in one direction („client?, „server?). •the client object can ask the server object to do something. •the client object can ask for data from the server object. 8 object interaction (2) •two numberdisplay objects store data on behalf of a clockdisplay object. –the clockdisplay is the „client? object. –the numberdisplay objects are the „server? objects. –the client calls methods in the server objects. object-oriented programming with java ahmed al-ajeli 9 method calling public void timetick() { minutes.increment() if(minutes.getvalue() == 0) { // it just rolled over! hours.increment() } updatingdisplay() } ‘client’ method ‘server’ methods internal/self method call 10 external method calls •general form: object . methodname ( params ) •examples: hours.increment() minutes.getvalue() nb: object, not class name dot notation object-oriented programming with java ahmed al-ajeli 11 internal method calls •no object name is required: updatingdisplay() •internal methods often have private visibility. –prevents them from being called from outside their defining class. 12 internal method private void updatingdisplay() { displaystring = hours.getdisplayvalue() + ":" + minutes.getdisplayvalue() } object-oriented programming with java ahmed al-ajeli 13 method calls •nb: a method call on another object of the same type would also be an external call. •„internal? means „this object?. •„external? means „any other object?, regardless of its type. 14 the this keyword •used to distinguish parameters and fields of the same name. e.g.: •public numberdisplay(int limit) { this.limit = limit value = 0 } •q- why are we doing this at all? a- the reason is readability of source code object-oriented programming with java ahmed al-ajeli 15 the debugger •a debugger is a software tool that helps in examining how an application executes •useful to find program errors - errors are commonly known as “bugs” •set breakpoints. •examine variables •step through code
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
|