Posts

Showing posts from October, 2024

Midterm Exam Contents for CS601 Principles of Software Development

[What I learned for half of my Semester] Aug 20th - Software Development Lifecycle Model (Waterfall, Spiral Model, Agile) Aug 22th - Agile - inspired SLDC models(Scrum, XP, TDD, Kansan, User Story, Use Case). User Requirements. OOP Design principles(Abstraction, Encapsulation, Inheritance, Polymorphism). Aug 27th - Immutability, Design Principles Content. Json Files. How to read Json Files?  How to make a class immutable?  Aug 29th - Data Structure Review(Array, ArrayList, Set, Map), Interfaces How interface is different from abstract method?  Aug 30th - Comparable / Comparator Interfaces  Sep 3rd - Iterable / Iterator. Sealed Interfaces  Sep 5th - Polymorphism, Dependency Injection. Composition. Inheritance Sep 10th - Inheritance Cont(Static Methods, instance of). Abstract Class.  When is downcast used?  Sep 12th - Liskov Substitution principle. Abstract classes cont. Nested Classes(Inner class, Static Nested Class, Anonymous Inner Class)  Sep 17...

Singleton Pattern

package designPatterns.creatingObjects.singleton; /** A good implementation of a Singleton pattern. * This implementation is thread-safe. * See other implementations in lecture slides. * From Joshua Bolch, Effective Java. * */ public class Singleton { private static Singleton instance = new Singleton(); // created when the class is loaded /** * Constructor is made private so that client cannot create instances */ private Singleton () {} /** No synchronization needed, since instance exists, so all threads are just reading * * @return instance of singleton */ public static Singleton getInstance () { return instance ; } } package designPatterns.creatingObjects.singleton; public class Driver { public static void main (String[] args) { Singleton s1 = Singleton. getInstance (); Singleton s2 = Singleton. getInstance (); System. out .println(s1 == s2); } }