Differences

This shows you the differences between two versions of the page.

Link to this comparison view

poo:laboratoare:11 [2025/12/14 17:32]
george.tudor1906
poo:laboratoare:11 [2025/12/14 17:54] (current)
george.tudor1906
Line 1: Line 1:
  
 ===== Laboratorul 11 – Design Patterns (1) ===== ===== Laboratorul 11 – Design Patterns (1) =====
 +
 +<​hidden>​
 +{{:​poo:​laboratoare:​rezolvare_dp_catalog.zip|}}
 +</​hidden>​
  
 === Problema 1 - Singleton === === Problema 1 - Singleton ===
Line 263: Line 267:
 } }
 </​code>​ </​code>​
- 
-=== Breviar - Builder Pattern === 
- 
-<code java> 
-public class User { 
-    private final String firstName; 
-    private final String lastName; 
-    private int age; 
-    private String phone; 
-    private String address; 
- 
-    private User(UserBuilder builder) { 
-        this.firstName = builder.firstName;​ 
-        this.lastName = builder.lastName;​ 
-        this.age = builder.age;​ 
-        this.phone = builder.phone;​ 
-        this.address = builder.address;​ 
-    } 
- 
-    public static class UserBuilder { 
-        private final String firstName; 
-        private final String lastName; 
-        private int age; 
-        private String phone; 
-        private String address; 
- 
-        public UserBuilder(String firstName, String lastName) { 
-            this.firstName = firstName; 
-            this.lastName = lastName; 
-        } 
- 
-        public UserBuilder age(int age) { 
-            this.age = age; 
-            return this; 
-        } 
- 
-        public UserBuilder phone(String phone) { 
-            this.phone = phone; 
-            return this; 
-        } 
- 
-        public UserBuilder address(String address) { 
-            this.address = address; 
-            return this; 
-        } 
- 
-        public User build() { 
-            return new User(this); 
-        } 
-    } 
- 
-    public static void main(String[] args) { 
-        User user1 = new User.UserBuilder("​Lokesh",​ "​Gupta"​) 
-                .age(30) 
-                .phone("​1234567"​) 
-                .address("​Fake address 1234") 
-                .build(); 
- 
-        User user2 = new User.UserBuilder("​Jack",​ "​Reacher"​) 
-                .age(40) 
-                .phone("​5655"​) 
-                //no address 
-                .build(); 
-    } 
-} 
-</​code>​ 
- 
  
poo/laboratoare/11.1765726377.txt.gz · Last modified: 2025/12/14 17:32 by george.tudor1906
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0