Skip to main content

Posts

Showing posts with the label Object-Oriented

Functional programming in Java 8

In my previous post , we discussed about why we should consider to use functional programming. Now, let's delve into what functional programming in Java is. What is pure functional programming? Shortly,  f unctional programming is programming using functions. A function corresponds to a mathematical function such as log, sin. Basically, it takes zero or more arguments, give one or more result, and has no side effects. We can't completely program in pure functional style in Java Why?  For example, calling Scanner.nextLine twice typically gives different result. So, it's just called "functional-style programming". How is that? - There is no mutating structures visible to callers. That means your side effect may not be visible to a program, but it's visible to the programmer in terms of slower execution. - A function or method shouldn't throw any exceptions (follows the concept "pass arguments, return result"). We can use types like Opti

Template Method Pattern: Don't Call Us, We'll Call You!

So far, the Template Method has been my most used design pattern. That is the reason why this post is quite long. J Definition from Wiki The Template Method defines the program skeleton of an algorithm in a method, deferring some steps to subclasses. It lets one redefine certain steps of an algorithm without changing the algorithm's structure. A Real World Use Case Imagine that you have many different kinds of documents. You want to generate a pdf file from a corresponding word template. Each type has its own small modifications but the main process for document generating is the same. We apply the Template Method for this case. We define a final method including some steps (such as preparing for content, generating file) at a superclass. There are three possibilities for these steps at subclasses: Must be overridden: abstract methods. Not mandatory to be overridden: default protected methods. Can not be overridden: default private methods. Dissecting the Patt

Agile Design

How can you design the software which is built in tiny increments? How can you ensure that the software has a good structure which is flexible, maintainable and reusable? ARE'NT YOU GOING TO MISS THE BIG PICTURE? Not really! In an agile team, the big picture evolves along with the software. How? With each iteration, the team improves the design of the system so that it is as good as it can be for the system as it is now. They focus on the current structure of the system, making it as good as it can be . How do we know if the design of software is good? Avoiding these following  symptoms of poor design (design smells) should be a way. 1. Rigidity - The design is hard to change. 2. Fragility - The design is easy to break. 3. Immobility - The design is hard to reuse. 4. Viscosity - It is hard to do the right thing. 5. Needless Complexity - Overdesign 6. Needless Repetition - Mouse abuse 7. Opacity - Disorganized expression These symptoms are similar in nature

Separate Constructing a System from Using It

I n the real world, in order to use a building (hotel, supermarket, etc) we need to construct it first. This concern should be applied for software development as well. Step by step, I would like to show you the issue about no separation of constructing and using it and then I'll give you some approaches to overcome this issue. | Note : you can find the  below  demonstrated code here    Take a Look the Following Simple Application Used tools and technologies: Eclipse (Mars), JDK 1.8 I had an App which uses Controller . Controller uses Service (an interface). Finally, Service has one concrete class is DefaultService . //package vn.nvanhuong.system.separationconstructing; public class App { public static void main(String[] args) { Controller controller = new Controller(); controller.doAction(); } } public class Controller { private Service service; public void doAction(){ System.out.println("doAction in Controller"); getService().execute();