Code Monkey home page Code Monkey logo

lab-padroes-projeto-java's Introduction

Explorando Padrões de Projetos na Prática com Java

Repositório com as implementações dos padrões de projeto explorados no Lab "Explorando Padrões de Projetos na Prática com Java". Especificamente, este projeto explorou alguns padrões usando Java puro:

  • Singleton
  • Strategy
  • Facade

lab-padroes-projeto-java's People

Contributors

falvojr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lab-padroes-projeto-java's Issues

Solução de padrões de projeto

public class Singleton {
private static Singleton instance;

private Singleton() {
    // Construtor privado para impedir a criação de instâncias diretas.
}

public static Singleton getInstance() {
    if (instance == null) {
        instance = new Singleton();
    }
    return instance;
}

}
// A classe Singleton garante que apenas uma instancia seja criada e fornecerá essa instancia sempre que getInstance() for chamado.


public interface PaymentStrategy {
void pay(int amount);
}

public class CreditCardPayment implements PaymentStrategy {
private String cardNumber;

public CreditCardPayment(String cardNumber) {
    this.cardNumber = cardNumber;
}

@Override
public void pay(int amount) {
    System.out.println("Pagamento de $" + amount + " com cartão de crédito " + cardNumber);
}

}

public class PayPalPayment implements PaymentStrategy {
private String email;

public PayPalPayment(String email) {
    this.email = email;
}

@Override
public void pay(int amount) {
    // Lógica para pagamento com PayPal
    System.out.println("Pagamento de $" + amount + " com PayPal usando o email " + email);
}

}

// Interface para a estratégia
// Implementações das estratégias
// Lógica para pagamento com PayPal
// Aqui, temos uma interface PaymentStrategy que define o contrato para as estratégias de pagamento. Em seguida, implementamos duas estratégias diferentes: CreditCardPayment e PayPalPayment.

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.