Static factory methods: No need of using multiple overloaded constructors. No need of memory allocation each time a new object is created. Object also can be returned. It encourages composition instead of inheritance.
Memory Leaks in Java: Assigning values to an array and leaving the array like that in memory even after array processing completes causes memory leaks. It can be avoided by nullifying the array. Use finalizes to remove the objects from memory. (object.terminate()) Exception:“OutOfMemory” exception.
Using classes in Java: We need to minimize the accessibility of classes and members. (Use private final as much as you can) Use composition in place of inheritance.
Immutable Objects: String, Integer etc… The states of these objects cannot change after construction. They are threading safe and exception on them is handled.
Composition instead of Inheritance: Just implement the desired functionality instead of inheriting the whole class.
No comments:
Post a Comment