Native Apps using web technologies - Titanium
Mobile Apps are the latest buzz!!! I want to dirty my hands and did basic research on what's involved.
The 1st question: Native apps or Web Apps?
Native apps has its own advantages but there will be steep learning curve and different code base for various platforms. So, my initial bias was more towards Web apps. But, performance and some limitations (unable to use platform specific features) are a bit of concern.
I have played with various frameworks and shortlisted the following two for in depth research.
Finally decided to use Titanium for following reasons:
- Active development
- Performance close to native apps
- Developer community
- Better documentation
- Exhaustive examples (Kitchen sink)
Playing it for the last couple of months and definitely recommended it.
A simple pattern for requirements analysis
The pattern
Take the following steps to develop a pattern for business stakeholder requirements descriptions:
1. Identify the business processes.Source: Nalla Senthilnathan
2. Identify the IT processes that support each of the business processes.
3. Identify the activities within each of the IT processes.
4. Identify the functions within each of the activities.
5. Identify the use cases for one or more of the functions.
IComparable vs IComparer interfaces in Visual C#
IComparable
The role of IComparable is to provide a method of comparing two objects of a particular type. This is necessary if you want to provide any ordering capability for your object. Think of IComparable as providing a default sort order for your objects. For example, if you have an array of objects of your type, and you call the Sort method on that array, IComparable provides the comparison of objects during the sort. When you implement the IComparable interface, you must implement the CompareTo method.
IComparer
The role of IComparer is to provide additional comparison mechanisms. For example, you may want to provide ordering of your class on several fields or properties, ascending and descending order on the same field, or both.
Using IComparer is a two-step process. First, declare a class that implements IComparer, and then implement the Compare method.
public class Car : IComparable
{
public int ID { get; set; }
public string PetName { get; set; }
public Car(string petName, int id)
{
PetName = petName;
ID = id;
}
// IComparable implementation.
int IComparable.CompareTo(object obj)
{
Car temp = (Car)obj;
return this.ID.CompareTo(temp.ID);
}
}
public class PetNameComparer : IComparer
{
// Test the pet name of each object.
int IComparer.Compare(object o1, object o2)
{
Car t1 = (Car)o1;
Car t2 = (Car)o2;
return String.Compare(t1.PetName, t2.PetName);
}
}
// Car[] cars = {...}; // Array of cars
// Following example uses IComparable interface
// Array.Sort(cars);
// Following example uses IComparer Interface
// Array.Sort(cars, new PetNameComparer());
Dispose pattern (C#)
Microsoft has defined a formal, prim-and-proper disposal pattern that strikes a balance between robustness, maintainability, and performance.
Here is a sample which makes use of this official pattern.
public class MyResourceWrapper : IDisposableSource: Pro C# 2008 and the .NET 3.5 Platform (Fourth Edition)
{
// Used to determine if Dispose()
// has already been called.
private bool disposed = false;
public void Dispose()
{
// Call our helper method.
// Specifying "true" signifies that
// the object user triggered the cleanup.
CleanUp(true);
// Now suppress finalization.
GC.SuppressFinalize(this);
}
private void CleanUp(bool disposing)
{
// Be sure we have not already been disposed!
if (!this.disposed)
{
// If disposing equals true, dispose all
// managed resources.
if (disposing)
{
// Dispose managed resources.
}
// Clean up unmanaged resources here.
}
disposed = true;
}
~MyResourceWrapper()
{
// Call our helper method.
// Specifying "false" signifies that
// the GC triggered the cleanup.
CleanUp(false);
}
}