Wednesday, May 8, 2013

PhoneInfo

Sometimes we have to develope on new / unknown devices. I just created one simple application which extracts almost everything you need; CPU/Hardware, Kernel, Display, Connectivity, Telephony states. It's on Github repository, and target SDK is API 17 (JB MR1). or else, get it on Google play.


Android app on Google Play

Friday, May 3, 2013

Patterns

Active record pattern


In software engineering, the active record pattern is an architectural pattern found in software that stores its data in relational databases. It was named by Martin Fowler in his 2003 book Patterns of Enterprise Application Architecture. The interface of an object conforming to this pattern would include functions such as Insert, Update, and Delete, plus properties that correspond more or less directly to the columns in the underlying database table. For example,

part = new Part()
part.name = "Sample part"
part.price = 123.45
part.save()

is equivalent to SQL command

INSERT INTO parts (name, price) VALUES ('Sample part', 123.45);

Also, below JAVA code:

b = part.find_first("name", "gearbox")

is equivalent to SQL command

SELECT * FROM parts WHERE name = 'gearbox' LIMIT 1;


Convention over configuration


Convention over configuration (also known as coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility.

Don't repeat yourself


In software engineering, don't repeat yourself (DRY) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures. The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."

Abstraction principle


software engineering and programming language theory, the abstraction principle (or the principle of abstraction) is a basic dictum that aims to reduce duplication of information in a program (usually with emphasis on code duplication) whenever practical by making use of abstractions provided by the programming language or software libraries. The principle is sometimes stated as a recommendation to the programmer, but sometimes stated as requirement of the programming language, assuming it is self-understood why abstractions are desirable to use. As a recommendation to the programmer, in its formulation by Benjamin C. Pierce in Types and Programming Languages (2002), the abstraction principle reads (emphasis in original): “Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts."

Model–view–controller a.k.a. MVC


Model–view–controller (MVC) is a software architecture pattern which separates the representation of information from the user's interaction with it. The model consists of application data, business rules, logic, and functions. A view can be any output representation of data, such as a chart or a diagram. Multiple views of the same data are possible, such as a bar chart for management and a tabular view for accountants. The controller mediates input, converting it to commands for the model or view. The central ideas behind MVC are code reusability and separation of concerns.

Singleton pattern


In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects. The term comes from the mathematical concept of a singleton.
  • Eager initialization
  • 
    public class Singleton {
        private static final Singleton instance = new Singleton();
     
        private Singleton() {}
     
        public static Singleton getInstance() {
            return instance;
        }
    }
    
  • Static block initialization
  • 
    public class Singleton {
      private static final Singleton instance;
     
      static {
        try {
          instance = new Singleton();
        } catch (IOException e) {
          throw new RuntimeException("Darn, an error occurred!", e);
        }
      }
     
      public static Singleton getInstance() {
        return instance;
      }
     
      private Singleton() {
        // ...
      }
    }
    
  • The solution of Bill Pugh
  • 
    public class Singleton {
            // Private constructor prevents instantiation from other classes
            private Singleton() { }
     
            /**
            * SingletonHolder is loaded on the first execution of Singleton.getInstance() 
            * or the first access to SingletonHolder.INSTANCE, not before.
            */
            private static class SingletonHolder { 
                    public static final Singleton INSTANCE = new Singleton();
            }
     
            public static Singleton getInstance() {
                    return SingletonHolder.INSTANCE;
            }
    }
    
  • The Enum way
  • 
    public enum Singleton {
            INSTANCE;
            public void execute (String arg) {
                    //... perform operation here ...
            }
    }