Saturday, February 6, 2010

Why do we use Interface?

Purposes of Interfaces

  • create loosely coupled software
  • support design by contract (an implementor must provide the entire interface)
  • allow for pluggable software
  • allow different objects to interact easily
  • hide implementation details of classes from each other
  • facilitate reuse of software
Analogy 1: Much like the US space shuttle, Russian Soyuz spacecraft and Chinese Shenzhou 5 can all dock to the International Space Station, because they implement the same docking interface. (This is the just an example - I don't know if it's true in real life however let's suspend our disbelief for the sake of an example)
Analogy 2: Like you can plug various computer monitors into your home computer. You can plug a wall-size TV into it, an old CRT (the thick kind), a 20" flat screen, or a braille machine for the blind to "see" by touch. There's compatibility among these various/different devices and your computer because they all agree on interface standards.

http://stackoverflow.com/questions/2026054/why-do-we-use-interface-is-it-only-for-standardization

When should one use interfaces?

In languages such as Java and C# interfaces provide a means for a class to be have in a polymorphic manner. That is to say a class can satisfy more than one contract - it can behave as multiple different types, a class of one type can be substituted for another. In other languages this can also be provided by multiple inheritance, but there are various disadvantages to this approach. However, having a class behave as more than one type is not the most common motivation for using interfaces.

By programming to interfaces instead of classes you can also decouple your program from specific implementations. This makes it much easier to substitute one class implementation for another. This is particularly useful when writing unit tests where you may wish to swap some heavyweight class implementation with a lightweight mock object. If your program only expects an interface type, and both the heavyweight object and mock object implement said interface, then they are very easy to substitute.

Also, consider a simple Java example where I say have a program that displays pages of data on the screen. Initially I want it to get the data from a database or XML files. If I write my program so that it uses interfaces I can define an interface like so:

And use it like so:

I can then write separate database and XML implementations that adhere to this interface:

Because I used an interface I can now use either implementation - Database or XML - interchangeably without having to change the parts of my program that ask for the page data. The XML and Database implementations likely do completely different things but all my program cares about is that the object supplying the page data implements the PageDatasource interface.

http://stackoverflow.com/questions/1686174/when-should-one-use-interfaces

Sunday, January 31, 2010

What are unit testing and integration testing, and what other types of testing should I know about?

  • unit testing in the sense of "testing the smallest isolatable unit of an application"; this is typically a method or a class, depending on scale
  • integration testing
  • feature testing - this may cut across units, and is the focus of TDD
  • black-box testing: testing only the public interface with no knowledge of how the thing works
  • glass-box testing: testing all parts of a thing with full knowledge of how it works
  • regression testing: test-cases constructed to reproduce bugs, to ensure that they do not reappear later
  • pointless testing: testing the same basic case more than one way, or testing things so trivial that they really do not need to be tested (like auto-generated getters and setters)
http://stackoverflow.com/questions/437897/what-are-unit-testing-and-integration-testing-and-what-other-types-of-testing-s

What is Unit test, Integration Test, Smoke test, Regression Test?

  • Unit test: Specify and test one point of the contract of single method of a class. This should have a very narrow and well defined scope. Complex dependencies and interactions to the outside world are stubbed or mocked.
  • Integration test: Test the correct inter-operation of multiple subsystems. There is whole spectrum there, from testing integration between two classes, to testing integration with the production environment.
  • Smoke test: A simple integration test where we just check that when the system under test is invoked it returns normally and does not blow up. It is an analogy with electronics, where the first test occurs when powering up a circuit: if it smokes, it's bad.
  • Regression test: A test that was written when a bug was fixed. It ensure that this specific bug will not occur again. The full name is "non-regression test".
To this, I will add:
  • Acceptance test: Test that a feature or use case is correctly implemented. It is similar to an integration test, but with a focus on the use case to provide rather than on the components involved.
http://stackoverflow.com/questions/4055736/what-is-a-smoke-test

Thursday, January 28, 2010

Are there automatic disqualifications for getting US security clearance?

I'll give you information about the process for obtaining a clearance.

SECRET:
NAC - National Agency Check - they'll take your fingerprints and name and run them through national crime databases (FBI database, NICS, etc) to check for any warrants.
LAC - Local Agency Check - they'll contact the police departments of any place in which you've lived, worked, or gone to school, and ask for a report of all contact they've ever had with you.
Credit check - they'll run your credit report to make sure you can't be easily bought out (ie, a hostile state offers to pay off your credit card in exchange for just a tiny bit of information).

TOP SECRET
The above, plus:
Field investigation - they'll contact the references you list and your neighbors for the past 7 years, and ask them a series of questions about you and your habits. They'll ask for recommendations to other people who have known you. They are trying to obtain a negative and positive view of your personality and habits to present to the Adjudicator.
Subject interview - speaks for itself.
Education - independent verification of all educational background claims.
Employment - independent verification of all past employment, including personal interviews of 2 colleagues where possible, and where employment exceeded 6 months.

For both, the Adjudicator will determine whether you are suitable for access to confidential information based on the guidelines listed here: http://fas.org/sgp/spb/class.htm If, based off those guidelines and the information they will collect, you feel that you will get rejected, then yes, you are wasting your time. If not, though, or if it's a "gray area," there should be a liaison you can talk to.

For Secret clearances, expect a wait time of 1-3 months (depending on how many previous addresses you have), and for TS clearances, expect to be waiting 6 months to 18 months (depending on the number of previous residences AND on whether something nasty pops up - ie, a past illicit drug use).
Source(s):
AD NCO serving in the USAF; I have a TS clearance

http://answers.yahoo.com/question/index?qid=20080927182741AAVhDab

Saturday, January 9, 2010

Factory Design Pattern

Idea is you extract the volatile core code and put it into external factory object. Instead of configuring factory at the time of construction (usual in Java), GoF factory design pattern says you should be able to create a general factory and then set the type of connection at the time of connection creation.

Saturday, January 2, 2010

Spring Tutorial 01 - Understanding Dependency Injection


Dependency Injection
A way to decouple dependencies between two objects so that they are not tied to each other.

Spring Tutorial 02 - Setting Up