dave45678 / basicoop Goto Github PK
View Code? Open in Web Editor NEWAnimal Class
Animal Class
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);
}
* 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...";
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.