Original from Ry’s Git Tutorial
###The Basics
git init Create a Git repository in the current folder.
git status View the status of each file in a repository.
git add <file> Stage a file for the next commit.
git commit Commit the staged files with a descriptive message.
git log View a repository’s commit history.
git config --global user.name "<name>" Define the author name to be used in all repositories.
Builder pattern is used to tackle problem where class contains a large number of optional parameters, besides builder pattern there are two other methods: Telescoping constructor pattern and JavaBeans Pattern, they all have some limits.
The telescoping constructor pattern works, but it is hard to write client code when there are many parameters, and harder still to read it In JavaBeans Pattern: JavaBean may be in an inconsistent state partway through its construction The JavaBeans Pattern precludes the possibility of making a class immutable The Builder pattern simulates named optional parameters in Python The Builder pattern is a good choice between when designing classes whose constructors or static factories would have more than a handful of parameters 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 // Telescoping constructor pattern - does not scale well!
A class can provide a public static factory method, which is simply a static method that returns an instance of the class.
Providing a static factory method instead of a public constructor has both advantages and disadvantages:
One advantage of static factory methods is that, unlike constructors, they have names, it can highlight differences between overloaded constructors. A second advantage of static factory methods is that, unlike constructors, they are not required to create a new obj each time they’re invoked.
Recently I changed my Mac package management tool from MacPorts to Homebrew, since Homebrew is lightweight and much faster, here is the steps I followed:
Remove MacPorts: 1 2 3 4 5 6 7 8 9 10 11 12 sudo port -f uninstall installed sudo rm -rf \ /opt/local \ /Applications/DarwinPorts \ /Applications/MacPorts \ /Library/LaunchDaemons/org.macports.* \ /Library/Receipts/DarwinPorts*.pkg \ /Library/Receipts/MacPorts*.pkg \ /Library/StartupItems/DarwinPortsStartup \ /Library/Tcl/darwinports1.
Singleton pattern ensures that there is only one instance of a class is created in JVM. It is used to provide global point of access to the object.
###Implementation example: Lazy initialization
1 2 3 4 5 6 7 8 9 10 11 12 public class Singleton { private static Singleton instance; private Singleton() { } public static Singleton getInstance() { if (instance == null) instance = new Singleton(); return instance; } } ###Implementation example: Eager initialization