Skip to main content

Posts

Showing posts with the label Software

Move like a Ninja on Terminal Console

If you are in IT and do a lot of stuff on terminal, this is the post for you. In the following post, we will explore various key shortcuts to jump and edit on console. Note:- Short keys may behave differnt on differnt OS systems. These keys best work with Linux sytem, For mac OS you have to enable Option key as Meta key in case of Alt . I have never checked these on windows, Please share your experinece with windows in comments. ------------------------------------------------------------------ Edit Control Move forward one char: Ctrl + f Move backward one char: Ctrl + b Move forward one word: Alt + f Move backward one word: Alt + b Move to end: Ctrl + e #Like End Move to start: Ctrl + a #Like Home Jump toggle between current location and start: Ctrl + xx Delete forward one char: Ctrl + d #Like Delete Delete backward one char: Ctrl + h #Like Backspace Delete forward one word: Alt + d Delete backward one word: Ctrl + w Delete to end: Ctrl + k Delete to start: Ctrl + u Undo: Ct...

Decorator Pattern : Real Life Example and Java Code Example

Decorator Pattern The Decorator Pattern provides a mechanism to dynamically attach the additional responsibilities to an object at runtime. Inheritance also provides the same but it is not flexible and does statically. We will see further in detail why Inheritance is not a good option as compared to Decorator Pattern. One important thing about the Decorator Pattern, It does not affect the core functionality just attach some additional. Real Life Example: Take the example of a bicycle store. When someone comes to buy a bicycle, The distributor shows the basic bicycle with core functionalities. After selecting the bicycle, He asks for the accessories you want to attach. Suppose there are accessories like carrier,stand-leg,front-light,front-box,bike-bell. The service man decorates your bicycle with accessories(additional functionalities without affecting the core functionality) as per your requirement. Java Code Example: We will try to implement the above real life exam...

Factory Pattern : Real Life Example and Java Code Example

Factory Pattern The Factory Pattern is actually a method(factory method) which is used to create objects on the basis of runtime requirements. Real Life Example: The factory method is same as the real world factory, It gives the same kind of object with different(based on the input) behavior. For example, There is a machine in a factory which takes wood and paints as input and gives a painted box as the final product. We can create different boxes by just changing the color of paint in the input. Java Code Example: Before going to codes, We need to see some key points about factory method implementation. We need an interface(Suppose A is an interface). Then We need various implementations of A (Suppose B, C, D are implementing A). Finally, We need a Factory class with a factory method. The factory method must have the return type of A. Find the below problem and its solution using the factory method. Suppose We need to build an application KNOW ABOUT ANIMALS. The a...

Singleton Pattern : Real Life Example and Java Code Example

Singleton Pattern The Singleton pattern uses to prevent the instantiation of an Object or creating a new one. It is used when We need only one instance in the whole application. The singleton is similar to global variables and we can find many debates over singleton vs global variables on the internet. We can choose between singleton and global variables based on the application context, But global variables violate the encapsulation policy of OOP concepts. Real Life Example: The DataSource is very good example of a singleton pattern. We initialize DataSourcet object by some parameters like host,port,user and password. Every time We need the DataSource, the values of the parameters remains same So We need exactly one instance of DataSource. Java Code Example: There is the various implementation of the singleton, based on the initialization like eager, lazy, static block and thread safe. Below implementation called Bill Pugh Singleton Implementation is simplest and also threa...

About Software Design and Development

When we plan to design a software we need to focus certain things. Here are some important points we can go through. Functional Decomposition: Functional decomposition is natural way to deal with complexity. The challenges with this approach: to dealing with change and bugs originate with changes to code. Low cohesion, tight coupling Focus on function leads to a cascade of changes from which it is difficult to escape. The Problem of Requirements: Requirements always change. Requirements are incomplete. Requirements are usually wrong. Requirements (and users) are misleading. Requirements do not tell the whole story. Deal with Changes(Use Functional Decomposition): Shift responsbility from yourself to...

Builder Pattern : Java Code Example

Builder Pattern Builder Pattern is used when the increase of object constructor parameter combination leads to an exponential list of constructors. It is a solution to the telescoping constructor anti-pattern. Let's describe the pattern by using a sample requirement. Problem: We need to create a class for a Customer in a Bank and need following attributes in the Customer object. {Name, Father's Name, Date Of Birth, Mobile, Email, PAN, Permanent Address, Correspondence Address, Account, Branch} Constraint : Name,Date Of Birth,Account can not be null or empty There are 10 attributes in the objects So there will be total 2^10(1024) possible constructor and It is not practical to write all required constructors. One alternative could be to use Setter method but it will not work if any attribute has final modifier and would be difficult to fulfill the constraint that some attributes can not be null or empty. Now We will see how Builder Design Pattern helps to solve...

Proxy Pattern : Real Life Example and Java Code Example

Proxy Pattern The proxy pattern defines how to get object level access control by acting as a pass through entity or a placeholder object. There are three types in the proxy pattern. (1) Remote Proxy: Remote proxy represents an object locally which belongs to a different remote location. Real Life Example: ATM is remote proxy for the banks. (2) Virtual Proxy: When an object is complex or heavy, We can use a virtual proxy object as a skeleton representation for the original object. Real Life Example: Bank Cheques are the Virtual Proxy for the Currency Notes. (3) Protection Proxy: When we use a proxy to restrict the access of object it's called Protection proxy. Real Life Example: Proxy servers used in office and organizations to block the access of some websites and networks Java Code Example: Below is the java code example for the ATM Bank Implementation(Remote Proxy). The below code is not very good and secure for sophisticated banking system and...

Observer Pattern : Real Life Example and Java Code Example

Observer Pattern The observer pattern defines a one to many relation between objects so that when one object changes state, all of its dependent or related objects get notified automatically Real Life Example: Group Chat is a real life example of observer pattern. Whenever someone type some text in text button and hit send button. Every member get notified that someone texted in group. Java Code Example: public interface Subject { void register(Observer observer); void remove(Observer observer); void notifyRespectedObserver(String msg); } public interface Observer { void update(String msg); String write(String msg); String getName(); } public class Console implements Subject { public List memberList; public Console(){ memberList = new LinkedList (); } public void register(Observer observer){ memberList.add(observer); } public void remove(Observer observer){ memberList.remove(observer); } public void notifyRespectedObserver(String msg){ for...

Design Pattern : Real Life Example and Java Code Example

                      I n software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into the source or machine code. It is a description or template for how to solve a problem that can be used in many different situations. - Wiki To explore the various kind of Design Patterns follow the below links. ----------------------------------------------------------------------------------------------------------------- Observer Pattern ----------------------------------------------------------------------------------------------------------------- Proxy Pattern ----------------------------------------------------------------------------------------------------------------- Builder Pattern ------------------------...