SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Object-Oriented Programming Language
                            Chapter 3 : Classes, Objects, and Methods


                                             Atit Patumvan
                             Faculty of Management and Information Sciences
                                           Naresuna University




Monday, November 21, 2011
2



                                                                                     Contents


             •        What Is an Object, Anyway?

             •        Instances and Methods

             •        An Objective-C Class for Working with Fractions

             •        The @interface Section

             •        The @implementation Section

             •        The program Section

             •        Accessing Instance Variable and Data Encapsulation




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University              Object-Oriented Programming Language
Monday, November 21, 2011
3



                                                       What Is an Object, Anyway?




                  Class                                                                             Instance/Object
                                                                                      create from
                                       Car                                                            myCar:Car


                                                                                     create from
                                                                                                     yourCar:Car



Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                              Object-Oriented Programming Language
Monday, November 21, 2011
4



                                                                Instances and Methods


              [ ClassOrInstance method ];

              yourCar                                         = [Car new];

                                                                                     message
                                                                                                 yourCar:Car
                                                                                               receiver
                                                  Sender

          [yourCar drive];
          [yourCar getGas: 30];
          currentMileage = [yourCar odometer];
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                             Object-Oriented Programming Language
Monday, November 21, 2011
5



                  An Objective-C Class for Working with Fractions

Program 3.1
  01:      #import <Foundation/Foundation.h>
  02:
  03:      int main (int argc, const char * argv[]) {
  04:          NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  05:
  06:      
         int numerator = 1;
  07:      
         int denominator = 3;
  08:      
  09:               NSLog(@"The fraction is %i/%i", numerator, denominator);
  10:               [pool drain];
  11:               return 0;
  12:      }
    :




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University   Object-Oriented Programming Language
Monday, November 21, 2011
6



                                                                The @interface Section

Program 3.2
    :
  03:      //---- @interface section ----                                                     Fraction
  04:
  05:      @interface Fraction: NSObject                                             numerator:int
  06:      {
  07:      
           int numerator;
                                                                                     denominator:int
  08:      
           int denominator;
  09:      }                                                                         print:void
  10:                                                                                setNumerator(int):void
  11:      -(void) print;                                                            setDenominator(int):void
  12:      -(void) setNumerator: (int) n;
  13:      -(void) setDenominator: (int) d;
  14:
  15:      @end
    :




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                 Object-Oriented Programming Language
Monday, November 21, 2011
7



                                                   The @implementation Section

Program 3.2
   :
 18:                                                                                          Fraction
 19:      @implementation Fraction
 20:
 21:      -(void) print
                                                                                     numerator:int
 22:      {                                                                          denominator:int
 23:      
          NSLog (@"%i/%i", numerator, denominator);
 24:      }                                                                          print:void
 25:                                                                                 setNumerator(int):void
 26:      -(void) setNumerator: (int) n;
 27:      {
                                                                                     setDenominator(int):void
 28:      
          numerator = n;
 29:      }
 30:
 31:      -(void) setDenominator: (int) d;
 32:      {
 33:      
          denominator = d;
 34:      }
 35:
 36:      @end
   :




Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                 Object-Oriented Programming Language
Monday, November 21, 2011
8



                                                                    The program Section

Program 3.2
   :
 40:      int main (int argc, const char * argv[]) {
 41:          NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 42:
 43:          // insert code here...
 44:      
          Fraction * myFraction;                                                                   Fraction
 45:      
 46:      
          myFraction = [Fraction alloc];                                                  numerator:int
 47:      
          myFraction = [myFraction init];
 48:      
                                                                               denominator:int
 49:      
 Set fraction to 1/3;
          //
 50:      
                                                                               print:void
 51:      
          [myFraction setNumerator: 1];                                                   setNumerator(int):void
 52:      
          [myFraction setDenominator: 3];                                                 setDenominator(int):void
 53:      
 54:      
 Display the fraction using the print method
          //
 55:
 56:      
          NSLog(@"The value of myFraction is:");
 57:      
          [myFraction print];                                                                myFraction:Fraction
 58:      
 59:      
          [myFraction release];
 60:
 61:      
          [pool drain];
 62:          return 0;
 63:      }
Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                     Object-Oriented Programming Language
Monday, November 21, 2011
9



        Accessing Instance Variables and Data Encapsulation

Program 3.4
 01:      @interface Fraction: NSObject                                                       Fraction
   :
 10:      -(int) numerator;
 11:      -(int) denominator;                                                        numerator:int
 12:                                                                                 denominator:int
 13:      @end
   :                                                                                 print():void
 17:      @implementation Fraction                                                   setNumerator(int):void
 18:
   :                                                                                 setDenominator(int):void
 34:      -(int) numerator                                                           numerator():int
 35:      {                                                                          denominator():int
 36:      
          return numerator;
 37:      }
 38:
 39:      -(int) denominator
 40:      {
 41:      
          return denominator;
 42:      }
 43:
 44:      @end
   :

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                 Object-Oriented Programming Language
Monday, November 21, 2011
10



        Accessing Instance Variables and Data Encapsulation

Program 3.4
   :
 52:      int main (int argc, const char * argv[]) {
 53:          NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 54:      
 55:          // insert code here...
 56:      
          Fraction * myFraction = [[Fraction alloc] init];                      Fraction
 57:      
 58:      
 Set fraction to 1/3;
          //
 59:      
                                                                     numerator:int
 60:      
          [myFraction setNumerator: 1];                              denominator:int
 61:      
          [myFraction setDenominator: 3];
 62:      
                                                          print():void
 63:      
 Display the fraction using our two new methods
          //                                                         setNumerator(int):void
 64:                                                                                 setDenominator(int):void
 65:      
          NSLog(@"The value of myFraction is:%i/%i",
                                                                                     numerator():int
 66:      
          
     [myFraction numerator],
 67:      
          
     [myFraction denominator]);                                           denominator():int
 68:      
 69:      
          [myFraction release];
 70:
 71:      
          [pool drain];
 72:          return 0;
 73:      }

Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University                 Object-Oriented Programming Language
Monday, November 21, 2011

Weitere ähnliche Inhalte

Was ist angesagt?

Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in PythonJuan-Manuel Gimeno
 
Writing Usable APIs in Practice by Giovanni Asproni
Writing Usable APIs in Practice by Giovanni AsproniWriting Usable APIs in Practice by Giovanni Asproni
Writing Usable APIs in Practice by Giovanni AsproniSyncConf
 
Producing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based FrameworkProducing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based FrameworkDaniele Gianni
 
Design and implementation of a java based virtual laboratory for data communi...
Design and implementation of a java based virtual laboratory for data communi...Design and implementation of a java based virtual laboratory for data communi...
Design and implementation of a java based virtual laboratory for data communi...IJECEIAES
 
turecko-150426_pse_01
turecko-150426_pse_01turecko-150426_pse_01
turecko-150426_pse_01Peter Fabo
 
Case study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureCase study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureHoneyChintal
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in pythonnitamhaske
 
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...Coen De Roover
 
Event-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling LanguagesEvent-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling LanguagesIstvan Rath
 
Animations On PDF Using Lua and LaTeX
Animations On PDF Using Lua and LaTeXAnimations On PDF Using Lua and LaTeX
Animations On PDF Using Lua and LaTeXMukund Muralikrishnan
 
Extractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language ModelExtractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language Modelgerogepatton
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and AlgorithmsPierre Vigneras
 

Was ist angesagt? (14)

Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in Python
 
Writing Usable APIs in Practice by Giovanni Asproni
Writing Usable APIs in Practice by Giovanni AsproniWriting Usable APIs in Practice by Giovanni Asproni
Writing Usable APIs in Practice by Giovanni Asproni
 
Producing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based FrameworkProducing simulation sequences by use of a Java-based Framework
Producing simulation sequences by use of a Java-based Framework
 
Design and implementation of a java based virtual laboratory for data communi...
Design and implementation of a java based virtual laboratory for data communi...Design and implementation of a java based virtual laboratory for data communi...
Design and implementation of a java based virtual laboratory for data communi...
 
turecko-150426_pse_01
turecko-150426_pse_01turecko-150426_pse_01
turecko-150426_pse_01
 
Case study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureCase study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structure
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
 
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
 
Unit 8
Unit 8Unit 8
Unit 8
 
Event-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling LanguagesEvent-driven Model Transformations in Domain-specific Modeling Languages
Event-driven Model Transformations in Domain-specific Modeling Languages
 
Animations On PDF Using Lua and LaTeX
Animations On PDF Using Lua and LaTeXAnimations On PDF Using Lua and LaTeX
Animations On PDF Using Lua and LaTeX
 
Extractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language ModelExtractive Summarization with Very Deep Pretrained Language Model
Extractive Summarization with Very Deep Pretrained Language Model
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Data Structures and Algorithms
Data Structures and AlgorithmsData Structures and Algorithms
Data Structures and Algorithms
 

Ähnlich wie OOP Chapter 3: Classes, Objects and Methods

OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping Atit Patumvan
 
IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...
IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...
IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...IRJET Journal
 
Recognition of Handwritten Mathematical Equations
Recognition of  Handwritten Mathematical EquationsRecognition of  Handwritten Mathematical Equations
Recognition of Handwritten Mathematical EquationsIRJET Journal
 
Computer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayListComputer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayListAtit Patumvan
 
A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...
A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...
A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...IRJET Journal
 
IRJET- Comparative Study of Different Techniques for Text as Well as Object D...
IRJET- Comparative Study of Different Techniques for Text as Well as Object D...IRJET- Comparative Study of Different Techniques for Text as Well as Object D...
IRJET- Comparative Study of Different Techniques for Text as Well as Object D...IRJET Journal
 
IRJET- Automated Detection of Gender from Face Images
IRJET-  	  Automated Detection of Gender from Face ImagesIRJET-  	  Automated Detection of Gender from Face Images
IRJET- Automated Detection of Gender from Face ImagesIRJET Journal
 
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...IRJET Journal
 
Real Time Sign Language Translation Using Tensor Flow Object Detection
Real Time Sign Language Translation Using Tensor Flow Object DetectionReal Time Sign Language Translation Using Tensor Flow Object Detection
Real Time Sign Language Translation Using Tensor Flow Object DetectionIRJET Journal
 
IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...
IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...
IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...IRJET Journal
 
End-to-End Object Detection with Transformers
End-to-End Object Detection with TransformersEnd-to-End Object Detection with Transformers
End-to-End Object Detection with TransformersSeunghyun Hwang
 
RESUME SCREENING USING LSTM
RESUME SCREENING USING LSTMRESUME SCREENING USING LSTM
RESUME SCREENING USING LSTMIRJET Journal
 
Smart debugger
Smart debuggerSmart debugger
Smart debuggerTao He
 
IRJET- Anomaly Detection System in CCTV Derived Videos
IRJET- Anomaly Detection System in CCTV Derived VideosIRJET- Anomaly Detection System in CCTV Derived Videos
IRJET- Anomaly Detection System in CCTV Derived VideosIRJET Journal
 
Packet Classification using Support Vector Machines with String Kernels
Packet Classification using Support Vector Machines with String KernelsPacket Classification using Support Vector Machines with String Kernels
Packet Classification using Support Vector Machines with String KernelsIJERA Editor
 

Ähnlich wie OOP Chapter 3: Classes, Objects and Methods (20)

OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping OOP Chapter 5 : Program Looping
OOP Chapter 5 : Program Looping
 
IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...
IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...
IRJET- Recognition of Handwritten Characters based on Deep Learning with Tens...
 
Recognition of Handwritten Mathematical Equations
Recognition of  Handwritten Mathematical EquationsRecognition of  Handwritten Mathematical Equations
Recognition of Handwritten Mathematical Equations
 
Computer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayListComputer Programming Chapter 6 : Array and ArrayList
Computer Programming Chapter 6 : Array and ArrayList
 
A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...
A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...
A WEB BASED APPLICATION FOR RESUME PARSER USING NATURAL LANGUAGE PROCESSING T...
 
IRJET- Comparative Study of Different Techniques for Text as Well as Object D...
IRJET- Comparative Study of Different Techniques for Text as Well as Object D...IRJET- Comparative Study of Different Techniques for Text as Well as Object D...
IRJET- Comparative Study of Different Techniques for Text as Well as Object D...
 
Resume
ResumeResume
Resume
 
Internshipppt.pptx
Internshipppt.pptxInternshipppt.pptx
Internshipppt.pptx
 
IRJET- Automated Detection of Gender from Face Images
IRJET-  	  Automated Detection of Gender from Face ImagesIRJET-  	  Automated Detection of Gender from Face Images
IRJET- Automated Detection of Gender from Face Images
 
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
 
Seminar
SeminarSeminar
Seminar
 
Real Time Sign Language Translation Using Tensor Flow Object Detection
Real Time Sign Language Translation Using Tensor Flow Object DetectionReal Time Sign Language Translation Using Tensor Flow Object Detection
Real Time Sign Language Translation Using Tensor Flow Object Detection
 
IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...
IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...
IRJET- Sentiment Analysis to Segregate Attributes using Machine Learning Tech...
 
End-to-End Object Detection with Transformers
End-to-End Object Detection with TransformersEnd-to-End Object Detection with Transformers
End-to-End Object Detection with Transformers
 
RESUME SCREENING USING LSTM
RESUME SCREENING USING LSTMRESUME SCREENING USING LSTM
RESUME SCREENING USING LSTM
 
Smart debugger
Smart debuggerSmart debugger
Smart debugger
 
IRJET- Anomaly Detection System in CCTV Derived Videos
IRJET- Anomaly Detection System in CCTV Derived VideosIRJET- Anomaly Detection System in CCTV Derived Videos
IRJET- Anomaly Detection System in CCTV Derived Videos
 
Packet Classification using Support Vector Machines with String Kernels
Packet Classification using Support Vector Machines with String KernelsPacket Classification using Support Vector Machines with String Kernels
Packet Classification using Support Vector Machines with String Kernels
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Resume_ml_db_cv
Resume_ml_db_cvResume_ml_db_cv
Resume_ml_db_cv
 

Mehr von Atit Patumvan

Iot for smart agriculture
Iot for smart agricultureIot for smart agriculture
Iot for smart agricultureAtit Patumvan
 
An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)Atit Patumvan
 
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตแบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตAtit Patumvan
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics toolsAtit Patumvan
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics toolsAtit Patumvan
 
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556Atit Patumvan
 
Chapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationChapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationAtit Patumvan
 
Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6Atit Patumvan
 
Computer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsComputer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsAtit Patumvan
 
Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Atit Patumvan
 
Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3Atit Patumvan
 
การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2Atit Patumvan
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1Atit Patumvan
 

Mehr von Atit Patumvan (20)

Iot for smart agriculture
Iot for smart agricultureIot for smart agriculture
Iot for smart agriculture
 
An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)An Overview of eZee Burrp! (Philus Limited)
An Overview of eZee Burrp! (Philus Limited)
 
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ตแบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
แบบฝึกหัดวิชา Theory of Computation ชุดที่ 1 เซ็ต
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics tools
 
Chapter 1 mathmatics tools
Chapter 1 mathmatics toolsChapter 1 mathmatics tools
Chapter 1 mathmatics tools
 
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
รายงานการประเมินคุณภาพภายใน ปีงบประมาณ 2556
 
Chapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computationChapter 0 introduction to theory of computation
Chapter 0 introduction to theory of computation
 
Media literacy
Media literacyMedia literacy
Media literacy
 
Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)Chapter 01 mathmatics tools (slide)
Chapter 01 mathmatics tools (slide)
 
การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8การบริหารเชิงคุณภาพ ชุดที่ 8
การบริหารเชิงคุณภาพ ชุดที่ 8
 
การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7การบริหารเชิงคุณภาพ ชุดที่ 7
การบริหารเชิงคุณภาพ ชุดที่ 7
 
การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6การบริหารเชิงคุณภาพ ชุดที่ 6
การบริหารเชิงคุณภาพ ชุดที่ 6
 
Computer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : MethodsComputer Programming Chapter 5 : Methods
Computer Programming Chapter 5 : Methods
 
Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops Computer Programming Chapter 4 : Loops
Computer Programming Chapter 4 : Loops
 
Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)
 
การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5การบริหารเชิงคุณภาพ ชุดที่ 5
การบริหารเชิงคุณภาพ ชุดที่ 5
 
การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4การบริหารเชิงคุณภาพ ชุดที่ 4
การบริหารเชิงคุณภาพ ชุดที่ 4
 
การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3การบริหารเชิงคุณภาพ ชุดที่ 3
การบริหารเชิงคุณภาพ ชุดที่ 3
 
การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2การบริหารเชิงคุณภาพ ชุดที่ 2
การบริหารเชิงคุณภาพ ชุดที่ 2
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1
 

Kürzlich hochgeladen

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Kürzlich hochgeladen (20)

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

OOP Chapter 3: Classes, Objects and Methods

  • 1. Object-Oriented Programming Language Chapter 3 : Classes, Objects, and Methods Atit Patumvan Faculty of Management and Information Sciences Naresuna University Monday, November 21, 2011
  • 2. 2 Contents • What Is an Object, Anyway? • Instances and Methods • An Objective-C Class for Working with Fractions • The @interface Section • The @implementation Section • The program Section • Accessing Instance Variable and Data Encapsulation Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 3. 3 What Is an Object, Anyway? Class Instance/Object create from Car myCar:Car create from yourCar:Car Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 4. 4 Instances and Methods [ ClassOrInstance method ]; yourCar = [Car new]; message yourCar:Car receiver Sender [yourCar drive]; [yourCar getGas: 30]; currentMileage = [yourCar odometer]; Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 5. 5 An Objective-C Class for Working with Fractions Program 3.1 01: #import <Foundation/Foundation.h> 02: 03: int main (int argc, const char * argv[]) { 04: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 05: 06: int numerator = 1; 07: int denominator = 3; 08: 09: NSLog(@"The fraction is %i/%i", numerator, denominator); 10: [pool drain]; 11: return 0; 12: } : Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 6. 6 The @interface Section Program 3.2 : 03: //---- @interface section ---- Fraction 04: 05: @interface Fraction: NSObject numerator:int 06: { 07: int numerator; denominator:int 08: int denominator; 09: } print:void 10: setNumerator(int):void 11: -(void) print; setDenominator(int):void 12: -(void) setNumerator: (int) n; 13: -(void) setDenominator: (int) d; 14: 15: @end : Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 7. 7 The @implementation Section Program 3.2 : 18: Fraction 19: @implementation Fraction 20: 21: -(void) print numerator:int 22: { denominator:int 23: NSLog (@"%i/%i", numerator, denominator); 24: } print:void 25: setNumerator(int):void 26: -(void) setNumerator: (int) n; 27: { setDenominator(int):void 28: numerator = n; 29: } 30: 31: -(void) setDenominator: (int) d; 32: { 33: denominator = d; 34: } 35: 36: @end : Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 8. 8 The program Section Program 3.2 : 40: int main (int argc, const char * argv[]) { 41: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 42: 43: // insert code here... 44: Fraction * myFraction; Fraction 45: 46: myFraction = [Fraction alloc]; numerator:int 47: myFraction = [myFraction init]; 48: denominator:int 49: Set fraction to 1/3; // 50: print:void 51: [myFraction setNumerator: 1]; setNumerator(int):void 52: [myFraction setDenominator: 3]; setDenominator(int):void 53: 54: Display the fraction using the print method // 55: 56: NSLog(@"The value of myFraction is:"); 57: [myFraction print]; myFraction:Fraction 58: 59: [myFraction release]; 60: 61: [pool drain]; 62: return 0; 63: } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 9. 9 Accessing Instance Variables and Data Encapsulation Program 3.4 01: @interface Fraction: NSObject Fraction : 10: -(int) numerator; 11: -(int) denominator; numerator:int 12: denominator:int 13: @end : print():void 17: @implementation Fraction setNumerator(int):void 18: : setDenominator(int):void 34: -(int) numerator numerator():int 35: { denominator():int 36: return numerator; 37: } 38: 39: -(int) denominator 40: { 41: return denominator; 42: } 43: 44: @end : Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011
  • 10. 10 Accessing Instance Variables and Data Encapsulation Program 3.4 : 52: int main (int argc, const char * argv[]) { 53: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 54: 55: // insert code here... 56: Fraction * myFraction = [[Fraction alloc] init]; Fraction 57: 58: Set fraction to 1/3; // 59: numerator:int 60: [myFraction setNumerator: 1]; denominator:int 61: [myFraction setDenominator: 3]; 62: print():void 63: Display the fraction using our two new methods // setNumerator(int):void 64: setDenominator(int):void 65: NSLog(@"The value of myFraction is:%i/%i", numerator():int 66: [myFraction numerator], 67: [myFraction denominator]); denominator():int 68: 69: [myFraction release]; 70: 71: [pool drain]; 72: return 0; 73: } Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Object-Oriented Programming Language Monday, November 21, 2011