и посмотреть медиа
Java | Interview questions
и посмотреть медиа
Questions and answers for Java developer interviews.
Questions and answers for Java developer interviews.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
Selection of typical questions in Java interviews: from JVM basics to Spring and Hibernate. Each question with detailed explanation, code examples, and tips. Suitable for all levels.
🤔 В чем разница между шаблоном проектирования Builder и Facade? 🚩`Builder` – создание сложных объектов Когда у объекта много параметров. Когда объект трудно создавать через конструктор. class Car { private String engine; private int wheels; private boolean sunroof; private Car(CarBuilder builder) { this.engine = builder.engine; this.wheels = builder.wheels; this.sunroof = builder.sunroof; } public static class CarBuilder { private String engine; private int wheels; private boolean sunroof; public CarBuilder setEngine(String engine) { this.engine = engine; return this; } public CarBuilder setWheels(int wheels) { this.wheels = wheels; return this; } public CarBuilder setSunroof(boolean sunroof) { this.sunroof = sunroof; return this; } public Car build() { return new Car(this); } } } Создаём объект пошагово Car car = new Car.CarBuilder() .setEngine("V8") .setWheels(4) .setSunroof(true) .build(); 🚩`Facade` – упрощение сложной системы Когда у системы много сложных классов, и вы хотите предоставить один упрощённый интерфейс. Когда нужно скрыть детали реализации от клиента. class CPU { void start() { System.out.println("Процессор запущен."); } } class Memory { void load() { System.out.println("Память загружена."); } } class HardDrive { void read() { System.out.println("Чтение данных с диска."); } } Создаём Facade, который скрывает сложность class ComputerFacade { private CPU cpu; private Memory memory; private HardDrive hardDrive; public ComputerFacade() { this.cpu = new CPU(); this.memory = new Memory(); this.hardDrive = new HardDrive(); } public void startComputer() { cpu.start(); memory.load(); hardDrive.read(); System.out.println("Компьютер включен!"); } } Теперь клиенту не нужно вызывать кучу методов ComputerFacade computer = new ComputerFacade(); computer.startComputer(); // Запускает всю систему через 1 метод Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!