Git Product home page Git Product logo

basicoop's People

Watchers

 avatar

Forkers

jbcapr19

basicoop's Issues

Cumpliendo DIP en la clase AnimalApp

Hola. Noté unas inconsistencias que pueden ser resueltas aplicando de forma correcta el principio de inversion de dependencias.
Definir 2 interfaces:

public interface IAnimal {
    public String sleep();
    public String eat();
}
public interface IVolador {
    public String fly();
}

Implementar las interfaces:

public class Animal implements IAnimal {
    private String color;
    private String name;
...
public class Bird extends Animal implements IVolador{

    public Bird() {
        // super();
        System.out.println("A bird is hatched...");
    }
...

Cumpliendo DIP:

public class AnimalApp {
    List<IAnimal> list;

    public AnimalApp(List<IAnimal> list){
        this.list = list;
    }

    public static void main(String[] args) {
        List<IAnimal> animales = new ArrayList<>();
        IAnimal a = new Animal();
        IAnimal c = new Cat();
        IAnimal b = new Bird();
        animales.add(a);
        animales.add(b);
        animales.add(c);

        AnimalApp system = new AnimalApp(animales);

    }

Untitled Diagram (3)

Cumpliendo LSP, en clase Bird


 * All Birds are Animals but all Animals are not Birds
 
    public class Bird extends Animal {
    public Bird() {
        // super();
        System.out.println("A bird is hatched...");
    }

    @Override
    public String sleep() {
        return "A bird sleeps soundly...";
    }

    @Override
    public String eat() {
        return "A bird eats...";
    }
}

* Class FlyingBird

      public class FlyingBird extends Bird {
               public String fly(){
               return "A bird flies...";
              }
      }

 * Example 

     public class Pinguino extends Bird {
        public Pinguino() {
            // super();
            System.out.println("A bird is hatched...");
        }

        @Override
        public String sleep() {
            return "A bird sleeps soundly...";
        }

        @Override
        public String eat() {
            return "A bird eats...";
        }

    }

    public class Sparrow extends FlyingBird {
        public Sparrow() {
            // super();
            System.out.println("A bird is hatched...");
        }

        @Override
        public String sleep() {
            return "A bird sleeps soundly...";
        }

        @Override
        public String eat() {
            return "A bird eats...";
        }

        @Override
        public String fly() {
            return "A bird flies...";
        }
 }

`
Class Diagram - LSP3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.