Download presentation
Presentation is loading. Please wait.
Published byStephen Elwin Rose Modified over 9 years ago
1
Computer Programming 2 Lecture 8: Object Oriented Programming Creating Classes & Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE
2
و من يتقِ الله... قال الله تعالى : ( وَإِبْرَاهِيمَ إِذْ قَالَ لِقَوْمِهِ اعْبُدُوا اللَّهَ وَاتَّقُوهُ ذَلِكُمْ خَيْرٌ لَكُمْ إِنْ كُنْتُمْ تَعْلَمُونَ ) ( العنكبوت :16) Mahmoud Rafeek Alfarra 2 Downloaded from http://staff.cst.ps/mfarra شريحـة ثابتـة لعلنا نحسن من خلالها أخلاقنـا و أفعالنا لنفوز يوم الامتحان الحقيقي
3
Out Lines Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 3 What is OOP? why? Main Concepts of OOP Thinking in Objects. Class & Object Access modifiers How To build Classes How To create Objects
4
What is OOP? Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 4 Object oriented programming, or OOP, is one model of programming language. Unlike other examples of computer programming language, object oriented programming focuses on the use of objects instead of actions in order to carry out tasks.
5
why? Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 5 Re-use: he power of object-oriented systems lies in their promise of code reuse which will increase productivity, reduce costs and improve software quality. Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.
6
Main Concepts of OOP Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 6 A computer language can be aid to be Object Oriented if it provides support for the following, which are presented by classes & objects: Abstraction Polymorphism Encapsulation Inheritance
7
Main Concepts of OOP Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 7 Encapsulation: The act of placing data and the operations that perform on that data in the same class. The class then becomes the 'capsule' or container for the data and operations.
8
Main Concepts of OOP Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 8 Inheritance: The reuse of base classes (superclasses) to form derived classes (subclasses). Methods and properties defined in the superclass are automatically shared by any subclass. طالب جامعي بكالوريوسدبلوم مدرسي ابتدائيإعداديثانوي
9
Main Concepts of OOP Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 9 Polymorphism: Same interface, different implementation. The ability to substitute one class for another.
10
Main Concepts of OOP Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 10 Different classes may contain the same method names, but the result which is returned by each method will be different as the code behind each method (the implementation) is different in each class.
11
Main Concepts of OOP Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 11 Abstraction: using the methods of classes without care how they are implemented. ؟
12
Thinking in Objects Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 12 Every thing in the world is an object of class which contains attributes behavior
13
Class & Object Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 13 A class is a blueprint, or prototype, that defines the variables (data) and the methods (operations) common to all objects of a certain kind. An instance of a class. A class must be instantiated into an object before it can be used in the software. More than one instance of the same class can be in existence at any one time.
14
Class & Object Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 14
15
Class & Object Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 15
16
How To build Classes? Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 16 Any Thing (Class) Any Thing (Class) Attributes Behavior Each one is a represented as a variable in class Each one is a represented as a variable in class Each one is a represented as a Method in class Each one is a represented as a Method in class
17
How To build Classes? Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 17 Bank Account ID, owner, amount, … Withdraw, deposit, transfer Each one is a represented as a variable in class Each one is a represented as a variable in class Each one is a represented as a Method in class Each one is a represented as a Method in class
18
How To build Classes? Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 18 Access_modifiers class class_name { Access_modifiers class_name() { } Access_modifiers class class_name { Access_modifiers class_name() { } Constructor method Which gives the initial values to the variables Reserved word Name of class, must match The identifier rules As public
19
Access Modifiers Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 19 private: private members are accessible only in the class itself package: package members are accessible in classes in the same package and the class itself protected: protected members are accessible in classes in the same package, in subclasses of the class, and in the class itself public: public members are accessible anywhere the class is accessible
20
Example: Student Class Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 20 Lname string Student_ID string Level int Tel string Gender string Program string Print_info Input: - return: void Print_info Input: - return: void Update_info Input: name or ID Return : void Update_info Input: name or ID Return : void Fname string
21
Example: Student Class Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 21 Instance variableConstructor
22
Example: Student Class Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 22 Method Overloaded Method
23
How To create Objects? Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 23 Class_name object_name = new Class_name (); Class_name object_name = new Class_name ( value1, value2 );
24
Example: Student Class (cont’) Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 24
25
Next Lecture … Mahmoud Rafeek Alfarra Downloaded from Downloaded from http://staff.cst.ps/mfarra 25 How to store Objects in Array & why?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.