Download presentation
Presentation is loading. Please wait.
Published byFrederick Hines Modified over 8 years ago
1
OOP Android Club 2015
2
DO NOT REMEMBER! TRY TO UNDERSTAND!
3
Agenda Class Object Encapsulation Abstraction Inheritance Polymorphism
4
WHAT is OOP? Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic.objects
5
Procedural programming
6
OOP
7
WHY to use OOP? Easy to design Easy to maintain Reusable code
8
HOW? Create Class Create Object of class
9
Class a class is an extensible program-code- template Includes: Variables Methods
10
Object Instance of class Экземпляр
11
Class example
12
Object example
13
Class iPhone: example public class Iphone { public static int capacity; public static String color; public void turnOn(){ System.out.println("Turning on"); }
14
Object iphone: example Iphone firstIphone = new Iphone(); firstIphone.capacity = 16; firstIphone.color = "White"; Iphone secondIphone = new Iphone(); firstIphone.capacity = 32; firstIphone.color = "Black";
15
Object iphone: practice Create new iphone object: thirdIphone Capacity: 128 Color: Gold Turn On
16
Class example
17
Object example
18
Create class: practice Create class: Android Create following Strings name head body rightHand leftHand rightLeg leftLeg
19
Class methods: practice Create method: jump Access modifier: public Returns: nothing Does: Print “Jumping android”
20
Class methods: practice 2 Create another method: dance Access modifier: public Returns: nothing Does: Print “Dancing like robot”
21
Object: practice ANVAR ANDREW ANDRUXA
22
Encapsulation Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.
23
Инкапсуляция Инкапсуляция (по-русски: «сокрытие») — это свойство объектов скрывать некоторые свои данные и способы их обработки (методы) от окружающей его цифровой среды и, в частности, от кривых ручонок малоопытных программистов, оставляя «снаружи» только необходимые и/или требуемые свойства и функциональные возможности.
24
Do not show process
25
Encapsulation: Hide process
26
Encapsulation: example int day; int hour; int minute; int second; public void setDay(int d) { this.day = d; } public int getDay() { return day; }
27
Encapsulation: practice Create getter&setter for hour Create getter&setter for minute Create getter&setter for second
28
Encapsulation: create object Clock clock = new Clock(); clock.setDay(17);
29
Create object: practice Set hour Set minute Set second
30
Create object: practice2 Create another Clock object: clock2 Set day: 18 Hour: 0 Minute:5 Second: 45
31
Create object: practice3 Create another Clock object: clock3 Set day: 17 Hour: 15 Minute: 5 Second: 45
32
Create object: constructor Constructor – method where we initialize our class Clock clock = new Clock();
33
Empty constructor: example public Clock(){ }
34
Constructor: example public Clock(){ day = 17; hour = 20; minute = 5; second = 45; }
35
Constructor: practice Create constructor inside Android class Default values: Head: “white” Body: “white” Right hand: “white” Left hand: “white” Right leg: “white” Left leg: “white”
36
Constructor: practice2 Create constructor for Iphone class Capacity: 16 Color: “Black”
37
Setting values with constructor public Clock(int d, int h, int m, int s){ day = d; hour = h; minute = m; second = s; }
38
Setting values: practice Open class: Iphone Create constructor Using this constructor, create object: Iphone object Pass values Capacity: 16 Color: “White”
39
Setting values: practice2 Open class: Android Create constructor Using this constructor, create object: andrey Pass values: Name: Andrey Set colors for body parts
40
SUPER PRACTICE Create Class: Book Variables: title, author, isbn Methods: getters & setters Create constructor Create one Book object, set values using setters Create another Book object, set values using constructor
41
Project Euler https://projecteuler.net/problem=1
42
Questions? Any questions?
43
Review Lynda.com – Chapter 9. Creating Custom Classes
44
Homework http://codingbat.com/java/Array-1
45
Thank you Thank you for your attention!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.