• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
A brief overview on java frameworks
 

A brief overview on java frameworks

on

  • 13,496 views

This presentation tries to provide a very brief introduction to some of the popular java frameworks and their design philosophies.

This presentation tries to provide a very brief introduction to some of the popular java frameworks and their design philosophies.

Statistics

Views

Total Views
13,496
Views on SlideShare
13,495
Embed Views
1

Actions

Likes
6
Downloads
169
Comments
0

1 Embed 1

http://localhost 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    A brief overview on java frameworks A brief overview on java frameworks Presentation Transcript

    •  Object Oriented Development Principles and their uses Standard(?) Design Patterns and their roles Patterns in Java and their uses Overview of Spring Framework Evolution of Java EE 6 – All the goodies are now in official package A brief introduction to JUnit – Test Driven Development in Java
    •  The special three – • Encapsulation – hiding the concrete implementations • Polymorphism – objects has more than one form • Inheritance – reusing functionalities And some of their derived form/application – • Program to an interface, not to an implementation • Favor object composition over inheritanceand much more, most notably, Design Patterns……………
    •  Single Responsibility Principle Open-Close Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
    •  A defining characteristics of a framework It’s all about moving away the flow of controls to the frameworks.
    •  Let us consider a program that perform some simple command line query – puts What is your name? name = gets process_name(name) puts What is your quest? quest = gets process_quest(quest)
    •  However, in a window system, I would write something like this – require tk root = TkRoot.new() name_label = TkLabel.new() {text "What is Your Name?"} name_label.pack name = TkEntry.new(root).pack name.bind("FocusOut") {process_name(name)} quest_label = TkLabel.new() {text "What is Your Quest?"} quest_label.pack quest = TkEntry.new(root).pack quest.bind("FocusOut") {process_quest(quest)} Tk.mainloop()
    •  The control of execution has been handed over to the windowing system. The control is Inverted, the framework calls the code rather than rather than the code calling the framework. This principle is also known as Hollywood Principle.
    •  Let us write a software component that provides a list of movies directed by a particular director – class MovieLister... public Movie[] moviesDirectedBy(String arg) { List allMovies = finder.findAll(); for (Iterator it = allMovies.iterator(); it.hasNext();) { Movie movie = (Movie) it.next(); if (!movie.getDirector().equals(arg)) it.remove(); } return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]); }
    •  moviesDirectedBy is dependent on the implementation of the finder object. Let’s make this method completely independent of how all the movies are being stored. So all the method does is refer to a finder, and all that finder does is know how to respond to the findAll method.
    •  It can be done easily by defining an interface – public interface MovieFinder { List findAll(); }
    •  Let’s provide a concrete implementation of MovieFinder - class MovieLister... private MovieFinder finder; public MovieLister() { finder = new ColonDelimitedMovieFinder("movies1.txt"); }
    •  Now we have a new problem – how to get an instance of the right finder implementation into place
    •  The implementation class for the finder isnt linked into the program at compile time. Instead we want this lister to work with any implementation, and for that implementation to be plugged in at some later point. The problem is how that link could be made so that lister class is ignorant of the implementation class, but can still talk to an instance to do its work.
    •  The basic idea of the Dependency Injection is to have a separate object, an assembler, that populates a field in the lister class with an appropriate implementation for the finder interface.
    •  Type 1 IoC - Interface Injection Type 2 IoC - Setter Injection Type 3 IoC - Constructor Injection
    •  Define a setter method for populating finder – class MovieLister... private MovieFinder finder; public void setFinder(MovieFinder finder) { this.finder = finder; }
    •  Similarly let us define a setter for the filename - class ColonMovieFinder... public void setFilename(String filename) { this.filename = filename; }
    •  The third step is to set up the configuration for the files. Spring supports configuration through XML files and also through code, but XML is the expected way to do it – <beans> <bean id="MovieLister" class="spring.MovieLister"> <property name="finder"> <ref local="MovieFinder"/> </property> </bean> <bean id="MovieFinder" class="spring.ColonMovieFinder"> <property name="filename"> <value>movies1.txt</value> </property> </bean> </beans>
    •  And then the test – public void testWithSpring() throws Exception{ ApplicationContext ctx = new FileSystemXmlApplicationContext("spring.xml"); MovieLister lister = (MovieLister)ctx.getBean("MovieLister"); Movie[] movies = lister.moviesDirectedBy("Sergio Leone"); assertEquals("Once Upon a Time in the West", movies[0].getTitle()); } WHERE DID THE new GO ?!
    •  Spring Google Guice – created by Google Pico Container Avalon Context and Dependency Injection – official Sun Java DI Container Seasar
    •  Assume you have a graphical class with many set...() methods. After each set method, the data of the graphics changed, thus the graphics changed and thus the graphics need to be updated on screen. Assume to repaint the graphics you must call Display.update().
    •  The classical approach is to solve this by adding more code. At the end of each set method you write – void set...(...) { : : Display.update(); }
    •  What will happen if there are 20-30 of these set methods ? Also whenever a new set-method is added, developers must be sure to not forget adding this to the end, otherwise they just created a bug.
    •  AOP solves this without adding tons of code, instead you add an aspect - after() : set() { Display.update(); } after running any method that is a set pointcut, run the following code.
    •  And you define a point cut – pointcut set() : execution(* set*(*) ) && this(MyGraphicsClass) && within(com.company.*); If a method is named set* (* means any name mightfollow after set), regardless of what the method returns(first asterisk) or what parameters it takes (third asterisk)and it is a method of MyGraphicsClass and this class ispart of the package com.company.*, then this is a set()pointcut.
    •  This example also shows one of the big downsides of AOP. It is actually doing something that many programmers consider an Anti-Pattern. The exact pattern is called Action at a distance. Action at a distance is an anti-pattern (a recognized common error) in which behavior in one part of a program varies wildly based on difficult or impossible to identify operations in another part of the program.
    •  AspectJ Spring Seasar
    •  Object-relational mapping is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a virtual object database that can be used from within the programming language. Its good for abstracting the datastore out in order to provide an interface that can be used in your code.
    •  Without ORM, we write code like this – String sql = "SELECT ... FROM persons WHERE id = 10"; DbCommand cmd = new DbCommand(connection, sql); Result res = cmd.Execute(); String name = res[0]["FIRST_NAME"]; With the help of ORM tools, we can do – Person p = repository.GetPerson(10); String name = p.FirstName; Or - Person p = Person.Get(Person.Properties.Id == 10);
    •  The SQL is hidden away from logic code. This has the benefit of allowing developers to more easily support more database engines. Developers can focus on writing the logic, instead of getting all the SQL right. The code will typically be more readable as well.
    •  Object-relational mapping is the Vietnam of our industry – Ted Neward. Developers are struggling for years with the huge mismatch between relational database models and traditional object models.
    •  Granularity – more classes than the number of corresponding tables. Subtyping Identity – primary key vs. object identity and object equality Associations – unidirectional in OOP vs. foreign keys. Data Navigation – walking the object graph vs. SQL joins
    •  Hibernate – the highly popular ORM tool for Java, has a corresponding .NET version too (NHibernate). Uses HQL. Java Persistence API – official sun java specification for managing persistence.
    •  Seam Framework – AJAX + JSF + JPA + EJB 3.0 + BPM Log4J – logging framework for Java JUnit – Test Driven Development in Java Maven – actually not a framework, more of a build system, but still………
    •  Wikipedia Personal Website of Martin Fowler Stackoverflow Official Spring Documentation Coding Horror Official Java EE 6 Tutorial
    • Questions?