🗊Презентация Java 4 WEB. Lesson 3 - OOP

Нажмите для полного просмотра!
Java 4 WEB. Lesson 3 - OOP, слайд №1Java 4 WEB. Lesson 3 - OOP, слайд №2Java 4 WEB. Lesson 3 - OOP, слайд №3Java 4 WEB. Lesson 3 - OOP, слайд №4Java 4 WEB. Lesson 3 - OOP, слайд №5Java 4 WEB. Lesson 3 - OOP, слайд №6Java 4 WEB. Lesson 3 - OOP, слайд №7Java 4 WEB. Lesson 3 - OOP, слайд №8Java 4 WEB. Lesson 3 - OOP, слайд №9Java 4 WEB. Lesson 3 - OOP, слайд №10Java 4 WEB. Lesson 3 - OOP, слайд №11Java 4 WEB. Lesson 3 - OOP, слайд №12Java 4 WEB. Lesson 3 - OOP, слайд №13Java 4 WEB. Lesson 3 - OOP, слайд №14Java 4 WEB. Lesson 3 - OOP, слайд №15Java 4 WEB. Lesson 3 - OOP, слайд №16Java 4 WEB. Lesson 3 - OOP, слайд №17Java 4 WEB. Lesson 3 - OOP, слайд №18Java 4 WEB. Lesson 3 - OOP, слайд №19Java 4 WEB. Lesson 3 - OOP, слайд №20Java 4 WEB. Lesson 3 - OOP, слайд №21Java 4 WEB. Lesson 3 - OOP, слайд №22Java 4 WEB. Lesson 3 - OOP, слайд №23Java 4 WEB. Lesson 3 - OOP, слайд №24Java 4 WEB. Lesson 3 - OOP, слайд №25Java 4 WEB. Lesson 3 - OOP, слайд №26Java 4 WEB. Lesson 3 - OOP, слайд №27Java 4 WEB. Lesson 3 - OOP, слайд №28Java 4 WEB. Lesson 3 - OOP, слайд №29Java 4 WEB. Lesson 3 - OOP, слайд №30Java 4 WEB. Lesson 3 - OOP, слайд №31Java 4 WEB. Lesson 3 - OOP, слайд №32Java 4 WEB. Lesson 3 - OOP, слайд №33Java 4 WEB. Lesson 3 - OOP, слайд №34Java 4 WEB. Lesson 3 - OOP, слайд №35Java 4 WEB. Lesson 3 - OOP, слайд №36Java 4 WEB. Lesson 3 - OOP, слайд №37Java 4 WEB. Lesson 3 - OOP, слайд №38Java 4 WEB. Lesson 3 - OOP, слайд №39Java 4 WEB. Lesson 3 - OOP, слайд №40Java 4 WEB. Lesson 3 - OOP, слайд №41Java 4 WEB. Lesson 3 - OOP, слайд №42Java 4 WEB. Lesson 3 - OOP, слайд №43Java 4 WEB. Lesson 3 - OOP, слайд №44Java 4 WEB. Lesson 3 - OOP, слайд №45Java 4 WEB. Lesson 3 - OOP, слайд №46

Содержание

Вы можете ознакомиться и скачать презентацию на тему Java 4 WEB. Lesson 3 - OOP. Доклад-сообщение содержит 46 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Java 4 WEB 
Lesson 3 - OOP
Описание слайда:
Java 4 WEB Lesson 3 - OOP

Слайд 2





Lesson goals
Class design
Implement encapsulation
Implement inheritance including visibility modifiers and composition
Implement polymorphism
Описание слайда:
Lesson goals Class design Implement encapsulation Implement inheritance including visibility modifiers and composition Implement polymorphism

Слайд 3





Object vs Class
Описание слайда:
Object vs Class

Слайд 4





Abstract Classes
May contain any number of methods including zero
If class has at least one abstract method – class is abstract
abstract void clean()
Abstract methods may not appear in a class that is not abstract
The first concrete subclass of an abstract class is required to implement all abstract methods that were not implemented by a superclass
Описание слайда:
Abstract Classes May contain any number of methods including zero If class has at least one abstract method – class is abstract abstract void clean() Abstract methods may not appear in a class that is not abstract The first concrete subclass of an abstract class is required to implement all abstract methods that were not implemented by a superclass

Слайд 5





Method vs Constructor
Method describes behavior
Method signature:
	 - name
	 - arguments (including order)
Specific method with the same to class name and without return statement called Constructor
Описание слайда:
Method vs Constructor Method describes behavior Method signature: - name - arguments (including order) Specific method with the same to class name and without return statement called Constructor

Слайд 6





Constructor
class Animal {
    String name;

    Animal() {
        this("No-Name");
    }

    public Animal(String name) {
        this.name = name;
    }
}

class Main{
    public static void main(String[] args) {
	 println(new Monkey());
	 println(new Monkey(2));
    }
}
Описание слайда:
Constructor class Animal { String name; Animal() { this("No-Name"); } public Animal(String name) { this.name = name; } } class Main{ public static void main(String[] args) { println(new Monkey()); println(new Monkey(2)); } }

Слайд 7





Overloading and Overriding
class Game {
    void play() {
        // move to the left
    }
}
Описание слайда:
Overloading and Overriding class Game { void play() { // move to the left } }

Слайд 8





Overriding rules
The access modifier must be the same or more accessible;
The return type must be the same or a more restrictive type, also known as covariant return types;
If any checked exceptions are thrown, only the same exceptions or subclasses of those exceptions are allowed to be thrown;
The methods must not be static. (If they are, the method is hidden and not overridden);
@Override - It is a great idea to get in the habit of using it in order to avoid accidentally overloading a method.
Описание слайда:
Overriding rules The access modifier must be the same or more accessible; The return type must be the same or a more restrictive type, also known as covariant return types; If any checked exceptions are thrown, only the same exceptions or subclasses of those exceptions are allowed to be thrown; The methods must not be static. (If they are, the method is hidden and not overridden); @Override - It is a great idea to get in the habit of using it in order to avoid accidentally overloading a method.

Слайд 9





Overloading precedence
Exact match by type
Matching a superclass type
Converting to a larger primitive type
Converting to an autoboxed type
Varargs
Описание слайда:
Overloading precedence Exact match by type Matching a superclass type Converting to a larger primitive type Converting to an autoboxed type Varargs

Слайд 10





Overloading precedence
class Overloading {
    static void overloadedMethod(int i) { // will enter if nothing is commented
        System.out.println("in int");
    }

    static void overloadedMethod(long i) { // will enter if comment 'int'
        System.out.println("in long");
    }

    static void overloadedMethod(Integer i) { // will enter if comment 'int' and 'long'
        System.out.println("in Integer");
    }

    static void overloadedMethod(Number i) { // will enter if comment 'int', 'long' and 'Integer'
        System.out.println("in Number");
    }

    static void overloadedMethod(int... i) { // will enter if comment 'int', 'long', 'Integer' and 'Number'
        System.out.println("in var arg");
    }

    public static void main(String[] args) {
        overloadedMethod(10);
    }
}
Описание слайда:
Overloading precedence class Overloading { static void overloadedMethod(int i) { // will enter if nothing is commented System.out.println("in int"); } static void overloadedMethod(long i) { // will enter if comment 'int' System.out.println("in long"); } static void overloadedMethod(Integer i) { // will enter if comment 'int' and 'long' System.out.println("in Integer"); } static void overloadedMethod(Number i) { // will enter if comment 'int', 'long' and 'Integer' System.out.println("in Number"); } static void overloadedMethod(int... i) { // will enter if comment 'int', 'long', 'Integer' and 'Number' System.out.println("in var arg"); } public static void main(String[] args) { overloadedMethod(10); } }

Слайд 11





Interface
Defines a set of public abstract methods, which classes implementing the interface must provide. 
Allows you to define what a class can do without saying how to do it (interface is a contract)
A class may implement multiple interfaces as well as extend classes that implement interfaces, allowing for limited multiple inheritance in Java
May extend other interfaces, although they may not extend a class and vice versa
May contain public static final constant values, public and private methods, public default methods.
Описание слайда:
Interface Defines a set of public abstract methods, which classes implementing the interface must provide. Allows you to define what a class can do without saying how to do it (interface is a contract) A class may implement multiple interfaces as well as extend classes that implement interfaces, allowing for limited multiple inheritance in Java May extend other interfaces, although they may not extend a class and vice versa May contain public static final constant values, public and private methods, public default methods.

Слайд 12





Interface
interface Walk {
    int someConst = 1;
    public static final int anotherConst = 1;

    boolean isQuadruped();
    
    private void doSomething() {
        //do some work
    }

    abstract double getMaxSpeed();
}

interface Run extends Walk {
    public abstract boolean canHuntWhileRunning();

    default double getMaxSpeed(){
        return 1;
    }
}
Описание слайда:
Interface interface Walk { int someConst = 1; public static final int anotherConst = 1; boolean isQuadruped(); private void doSomething() { //do some work } abstract double getMaxSpeed(); } interface Run extends Walk { public abstract boolean canHuntWhileRunning(); default double getMaxSpeed(){ return 1; } }

Слайд 13





Interface
Provides a way for one individual to develop code that uses another individual’s code, without having access to the other individual’s underlying implementation. Interfaces can facilitate rapid application development by enabling development teams to create applications in parallel, rather than being directly dependent on each other (for example one team uses interface, another team implements it)
Описание слайда:
Interface Provides a way for one individual to develop code that uses another individual’s code, without having access to the other individual’s underlying implementation. Interfaces can facilitate rapid application development by enabling development teams to create applications in parallel, rather than being directly dependent on each other (for example one team uses interface, another team implements it)

Слайд 14





Functional interface
@FunctionalInterface
interface Speakable {
    String say();

    static void someStatic(){}
    
    default void someDefault(){}
    private void doSomething(){}
}
Описание слайда:
Functional interface @FunctionalInterface interface Speakable { String say(); static void someStatic(){} default void someDefault(){} private void doSomething(){} }

Слайд 15





Nested Classes
Types of nested classes: 
A member inner class is a class defined at the same level as instance variables. It is not static. Often, this is just referred to as an inner class without explicitly saying the type.
A local inner class is defined within a method.
An anonymous inner class is a special case of a local inner class that does not have a name. 
A static nested class is a static class that is defined at the same level as static variables.
Описание слайда:
Nested Classes Types of nested classes: A member inner class is a class defined at the same level as instance variables. It is not static. Often, this is just referred to as an inner class without explicitly saying the type. A local inner class is defined within a method. An anonymous inner class is a special case of a local inner class that does not have a name. A static nested class is a static class that is defined at the same level as static variables.

Слайд 16





Nested Classes
encapsulate helper classes by restricting them to the containing class
make it easy to create a class that will be used in only one place
can make the code easier to read.
Описание слайда:
Nested Classes encapsulate helper classes by restricting them to the containing class make it easy to create a class that will be used in only one place can make the code easier to read.

Слайд 17





Member Inner Classes
class A {
    private int x = 1;

    class B {
        private int x = 2;

        class C {
            private int x = 3;

            public void printAll() {
                System.out.println(x); // 3
                System.out.println(this.x); // 3
                System.out.println(B.this.x); // 2
                System.out.println(A.this.x); // 1
            }
        }
    }
}
Описание слайда:
Member Inner Classes class A { private int x = 1; class B { private int x = 2; class C { private int x = 3; public void printAll() { System.out.println(x); // 3 System.out.println(this.x); // 3 System.out.println(B.this.x); // 2 System.out.println(A.this.x); // 1 } } } }

Слайд 18





Local Inner Classes
class Outer {
    private int length = 5;

    public void calculate() {
        final int width = 20;
        class Inner {
            public void multiply() {
                System.out.println(length * width);
            }
        }
        Inner inner = new Inner();
        inner.multiply();
    }
}
Описание слайда:
Local Inner Classes class Outer { private int length = 5; public void calculate() { final int width = 20; class Inner { public void multiply() { System.out.println(length * width); } } Inner inner = new Inner(); inner.multiply(); } }

Слайд 19





Anonymous Inner Classes
public static void main(String[] args) throws Exception {
    JButton button = new JButton("red");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // handle the button click
        }
    });
}
Описание слайда:
Anonymous Inner Classes public static void main(String[] args) throws Exception { JButton button = new JButton("red"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // handle the button click } }); }

Слайд 20





Static Nested Classes
class Enclosing {
    static class Nested {
        private int price = 6;
    }

    public static void main(String[] args) {
        Nested nested = new Nested();
        System.out.println(nested.price);
    }
}
Описание слайда:
Static Nested Classes class Enclosing { static class Nested { private int price = 6; } public static void main(String[] args) { Nested nested = new Nested(); System.out.println(nested.price); } }

Слайд 21





Enum
A special data type that enables for a variable to be a set of predefined constants
Has unique set of values
Can implement interface
Can NOT extend class
Can contain fields and methods
Singleton
Описание слайда:
Enum A special data type that enables for a variable to be a set of predefined constants Has unique set of values Can implement interface Can NOT extend class Can contain fields and methods Singleton

Слайд 22





Enum
enum Planet implements IGravitable {
    MERCURY (3.303e+23, 2.4397e6) {
        @Override
        double surfaceGravity() {
            return -1;
        }
    }, 
    VENUS   (4.869e+24, 6.0518e6),
    EARTH   (5.976e+24, 6.37814e6)
    //    ...
    ;
    
    private double mass;   // in kilograms
    final double radius;   // in meters

    Planet(double mass, double radius) {// private
        this.mass = mass;
        this.radius = radius;
    }

    // universal gravitational constant  (m3 kg-1 s-2)
    public static final double G = 6.67300E-11;

    @Override
    double surfaceGravity() {
        return G * mass / (radius * radius);
    }
}
Описание слайда:
Enum enum Planet implements IGravitable { MERCURY (3.303e+23, 2.4397e6) { @Override double surfaceGravity() { return -1; } }, VENUS (4.869e+24, 6.0518e6), EARTH (5.976e+24, 6.37814e6) // ... ; private double mass; // in kilograms final double radius; // in meters Planet(double mass, double radius) {// private this.mass = mass; this.radius = radius; } // universal gravitational constant (m3 kg-1 s-2) public static final double G = 6.67300E-11; @Override double surfaceGravity() { return G * mass / (radius * radius); } }

Слайд 23





Design principle
A design principle is an established idea or best practice that facilitates the software design process.
Описание слайда:
Design principle A design principle is an established idea or best practice that facilitates the software design process.

Слайд 24





Design principle
More logical code
Code that is easier to understand 
Classes that are easier to reuse in other relationships and applications 
Code that is easier to maintain and that adapts more readily to changes in the application requirements
Описание слайда:
Design principle More logical code Code that is easier to understand Classes that are easier to reuse in other relationships and applications Code that is easier to maintain and that adapts more readily to changes in the application requirements

Слайд 25





OOP principles
Class
Object
Inheritance
Encapsulation
Polymorphism
Описание слайда:
OOP principles Class Object Inheritance Encapsulation Polymorphism

Слайд 26





OOP principles
Everything is object
Object is a class instance
Program – a set of interacting objects
Object has a state and behavior
Описание слайда:
OOP principles Everything is object Object is a class instance Program – a set of interacting objects Object has a state and behavior

Слайд 27





Access modifiers
public class Dog {
    public String name = "Scooby-doo";
    protected boolean hasFur = true;
    boolean hasPaws = true;
    private int id;
}
Описание слайда:
Access modifiers public class Dog { public String name = "Scooby-doo"; protected boolean hasFur = true; boolean hasPaws = true; private int id; }

Слайд 28





Encapsulation
Описание слайда:
Encapsulation

Слайд 29





Encapsulation
Описание слайда:
Encapsulation

Слайд 30





Encapsulation
No actor other than the class itself should have direct access to its data. The class is said to encapsulate the data it contains and prevent anyone from directly accessing it. 
With encapsulation, a class is able to maintain certain invariants about its internal data. An invariant is a property or truth that is maintained even after the data is modified.
Описание слайда:
Encapsulation No actor other than the class itself should have direct access to its data. The class is said to encapsulate the data it contains and prevent anyone from directly accessing it. With encapsulation, a class is able to maintain certain invariants about its internal data. An invariant is a property or truth that is maintained even after the data is modified.

Слайд 31





Encasulation example
class CoffeeMachine {
    private int sugar;
    private double milk;

    Coffee makeCoffee(){
        blendBeans();
        heatWater();
        shakeMilk();
        return mix();
    }

    private Coffee mix() {
        return new Coffee(); // mix all together
    }

    private void shakeMilk() {
        // shaking milk
    }

    private void heatWater() {
        // heating water
    }

    private void blendBeans() {
        // blending beans
    }
}
Описание слайда:
Encasulation example class CoffeeMachine { private int sugar; private double milk; Coffee makeCoffee(){ blendBeans(); heatWater(); shakeMilk(); return mix(); } private Coffee mix() { return new Coffee(); // mix all together } private void shakeMilk() { // shaking milk } private void heatWater() { // heating water } private void blendBeans() { // blending beans } }

Слайд 32





Encapsulation. Java Beans
A JavaBean is a design principle for encapsulating data in an object in Java. 
private properties
public getter(get, is for primitive boolean)
public setter (set)
property name in getter/setter starts with uppercase
Описание слайда:
Encapsulation. Java Beans A JavaBean is a design principle for encapsulating data in an object in Java. private properties public getter(get, is for primitive boolean) public setter (set) property name in getter/setter starts with uppercase

Слайд 33





Encapsulation. Java Beans
What is wrong


class Girl {
    private boolean playing;
    private Boolean dancing;
    public String name;
    …
}
Описание слайда:
Encapsulation. Java Beans What is wrong class Girl { private boolean playing; private Boolean dancing; public String name; … }

Слайд 34





Encapsulation. Java Beans
What is wrong


class Girl {
    private boolean playing;
    private Boolean dancing;
    public String name;
    …
}
Описание слайда:
Encapsulation. Java Beans What is wrong class Girl { private boolean playing; private Boolean dancing; public String name; … }

Слайд 35





Polymorphism
An object in Java may take on a variety of forms, in part depending on the reference used to access the object. 
One name, many forms. Polymorphism manifests itself by having multiple methods all with the same name, but slightly different functionality.
There are 2 basic types of polymorphism. 
Overriding, also called run-time (dynamic) polymorphism. 
Overloading, which is referred to as compile-time (static) polymorphism.
Описание слайда:
Polymorphism An object in Java may take on a variety of forms, in part depending on the reference used to access the object. One name, many forms. Polymorphism manifests itself by having multiple methods all with the same name, but slightly different functionality. There are 2 basic types of polymorphism. Overriding, also called run-time (dynamic) polymorphism. Overloading, which is referred to as compile-time (static) polymorphism.

Слайд 36





Polymorphism
	The type of the object determines which properties exist within the object in memory. 
	The type of the reference to the object determines which methods and variables are accessible to the Java program
Описание слайда:
Polymorphism The type of the object determines which properties exist within the object in memory. The type of the reference to the object determines which methods and variables are accessible to the Java program

Слайд 37





Polymorphism
interface LivesInOcean {
    void makeSound();
}

class Dolphin implements LivesInOcean {
    public void makeSound() {
        System.out.println("whistle");
    }
}

class Whale implements LivesInOcean {
    public void makeSound() {
        System.out.println("sing");
    }
}
Описание слайда:
Polymorphism interface LivesInOcean { void makeSound(); } class Dolphin implements LivesInOcean { public void makeSound() { System.out.println("whistle"); } } class Whale implements LivesInOcean { public void makeSound() { System.out.println("sing"); } }

Слайд 38





Polymorphism
class Primate {
    public boolean hasHair() {
        return true;
    }
}

interface HasTail {
    boolean isTailStriped();
}
class Lemur extends Primate implements HasTail {
    public int age = 10;

    public boolean isTailStriped() {
        return false;
    }
}
Описание слайда:
Polymorphism class Primate { public boolean hasHair() { return true; } } interface HasTail { boolean isTailStriped(); } class Lemur extends Primate implements HasTail { public int age = 10; public boolean isTailStriped() { return false; } }

Слайд 39





Inheritance (is-a)
Описание слайда:
Inheritance (is-a)

Слайд 40





Inheritance (is-a)
Описание слайда:
Inheritance (is-a)

Слайд 41





Virtual methods invocation
Описание слайда:
Virtual methods invocation

Слайд 42





Composition (has-a)
Object composition is the idea of creating a class by connecting other classes as members using the has‐a principle. 
Inheritance is the idea of creating a class that inherits all of its reusable methods and objects from a parent class. 
Both are used to create complex data models, each with its own advantages and disadvantages
Описание слайда:
Composition (has-a) Object composition is the idea of creating a class by connecting other classes as members using the has‐a principle. Inheritance is the idea of creating a class that inherits all of its reusable methods and objects from a parent class. Both are used to create complex data models, each with its own advantages and disadvantages

Слайд 43





Composition (has-a)
class Person {
    Job job;

    public Person() {
        this.job = new Job();
        job.setSalary(1000L);
    }

    public long getSalary() {
        return job.getSalary();
    }

}
Описание слайда:
Composition (has-a) class Person { Job job; public Person() { this.job = new Job(); job.setSalary(1000L); } public long getSalary() { return job.getSalary(); } }

Слайд 44





Literature
https://docs.oracle.com/javase/tutorial/java/javaOO/index.html
https://docs.oracle.com/javase/tutorial/java/IandI/index.html
https://docs.oracle.com/javase/tutorial/java/concepts/index.html
Описание слайда:
Literature https://docs.oracle.com/javase/tutorial/java/javaOO/index.html https://docs.oracle.com/javase/tutorial/java/IandI/index.html https://docs.oracle.com/javase/tutorial/java/concepts/index.html

Слайд 45





Homework
Implement classes: SUV, Sedan, Hatchback3Doors, Hatchback5Doors
SUV, Sedan, Hatchback3Doors, Hatchback5Doors should extend Vehicle
Vehicle provides info: name, max passengers number, number of doors
Vehicle should implement Drivable
Each Vehicle contains Accelerator, BrakePedal, Engine, GasTank, SteeringWheel
Implement Accelerator, BrakePedal, Engine, GasTank, SteeringWheel according to their names:
Accelerator works 5 seconds (5 times) and speed-up the car for a some accelerateStrength
BrakePedal slow down the car for a some brakingStrength
Engine hat it capacity, max speed, can be started or stopped, uses fuel from GasTank when work
GasTank has it max and current volumes, GasTank can use fuel  or can be filled by it
SteeringWheel has it max turn angle, current turn angle and step (one turn changes the current angle for this value), SteeringWheel can be turned left or right
Verify all properties of each car part they cannot be greater than some max value and less than some min value (see tests); speed, volume cannot be negative or greater than max speed and/or volume
Engine, GasTank, SteeringWheel should implement interface StatusAware
Create class ControlPanel that must control the Drivable regardless of what type of vehicle it is transmitted
Описание слайда:
Homework Implement classes: SUV, Sedan, Hatchback3Doors, Hatchback5Doors SUV, Sedan, Hatchback3Doors, Hatchback5Doors should extend Vehicle Vehicle provides info: name, max passengers number, number of doors Vehicle should implement Drivable Each Vehicle contains Accelerator, BrakePedal, Engine, GasTank, SteeringWheel Implement Accelerator, BrakePedal, Engine, GasTank, SteeringWheel according to their names: Accelerator works 5 seconds (5 times) and speed-up the car for a some accelerateStrength BrakePedal slow down the car for a some brakingStrength Engine hat it capacity, max speed, can be started or stopped, uses fuel from GasTank when work GasTank has it max and current volumes, GasTank can use fuel or can be filled by it SteeringWheel has it max turn angle, current turn angle and step (one turn changes the current angle for this value), SteeringWheel can be turned left or right Verify all properties of each car part they cannot be greater than some max value and less than some min value (see tests); speed, volume cannot be negative or greater than max speed and/or volume Engine, GasTank, SteeringWheel should implement interface StatusAware Create class ControlPanel that must control the Drivable regardless of what type of vehicle it is transmitted

Слайд 46


Java 4 WEB. Lesson 3 - OOP, слайд №46
Описание слайда:



Теги Java 4 WEB. Lesson 3 - OOP
Похожие презентации
Mypresentation.ru
Загрузить презентацию