Skip to main content

Unit Testing Native C++ App with out clr

· One min read

Unit Testing Native C++ Applications with out “/clr” flag or fall back to 3rd party frameworks

Visual Studio 11 provides the ability to do Unit Testing Native C++ Applications with a new C++ unit testing framework shipping with VS 11.

So the C++ developers no longer need to use the “/clr” flag or fall back to 3rd party frameworks.

To learn more about native unit testing in Visual Studio 11, please visit MSDN.

COM Containment and Aggregation

· One min read

Containment and aggregation are techniques in which one component uses another component. Those two components are outer component, inner component. Outer component contains the inner component.

ContainmentAggregation
Outer component re implement the interface say IY of inner component by forwarding calls to the inner component.Outer component will not re implement the interface say IY of inner component. Instead the outer component passes the inner component interface pointer say IY directly to the client.
Outer component is client to inner componentInner component will be directly used by the client

N-Tier Architecture

· One min read

N-Tier Architecture with ASP.NET MVC3, WCF and Entity Framework.

Advantage of using N-Tier software architecture are scalability, security, fault tolerance and etc. This article tries to introduce a decoupled, unit-testable, deployment-flexible, implementation-efficient and validation-flexible N-Tier architecture in .NET

Continue reading →

Attended Microsoft Devcon 2012

· One min read

Today (21-April-2012) I had attended the DevCon 2012 hosted at Microsoft's Gachibowli Campus.  DevCon is the event which concentrates on the latest technologies which are exclusively intended for .Net Developers.

devcon2012

The sessions that I had attended:

  1. Developing a Windows 8 Metro Style Application using HTML5 & JavaScript

    • Pratap Ladhani Architect - Microsoft
  2. SQL Server 2012 code name Denali & Programmability Enhancements

    • Sandeep Kumar Mishra MPSIT Engineering - Microsoft IT
  3. The New Age Application with HTML 5 and Kendo UI

    • Abhishek Kant Country Manager - Telerik, India
    • Svetlina Anti Software Developer - Telerik
  4. Conceptual Framework of Data Binding in XAML

    • Miroslav Nedyalkov Senior Software Developer - Telerik

Interacted with: Harish Ranganthan who is a 'Microsft Developer Evangelist' thanks to Harish as he given me a chance to explore his Windows 8 slate

  • Abhijit Jana Microsoft Associate Consultant

  • Shudhakar Microsoft

  • Shravan Kumar Kasagoni Microsoft MVP

Part-1: C++, C#, Java Syntax Differences

· One min read

C++ Main Function

  1. Main function with out any arguments
void main() { 
cout<<"Hello World !!!";
}
  1. Main function with commandline Arguments
int main(int argc, char* argv[]) {
cout<<"Hello World !!!";
return 1;
}

C# Main Function

  1. Main function with out any arguments
using System; 
namespace CSharpSample {
class Program {
static void Main() {
Console.WriteLine("Hello World !!!");
}
}
}
  1. Main Function with commandline Arguments
 using System; 
namespace CSharpSample {
class Program {
static int Main(string[] args) {
Console.WriteLine("Hello World !!!");
return 1;
}
}
}

Java Main function

  1. Main function with out any arguments Not possible Compilation error java.lang.NoSuchMethodError: main Exception in thread "main" Main function with commandline Arguments

  2. Main Function with commandline Arguments

public class Program { 
public static void main(String args[]) {
System.out.println( "Hello, World !!!" );
}
}

Part-2: C++, C#, Java Syntax Differences

· 2 min read

[Part-2: Basic Input/Output] C++, C#, Java Syntax Differences

Basic Input/Output

Using the standard input and output library, we will be able to interact with the user by printing messages on the screen and getting the user's input from the keyboard.

1. C++

  • Input    - cin>>
  • Output - cout<<
// Print Greetings Program
// Basic Input/Output
void PrintGreeting(char name[])
{
cout<<"Hello " << name <<endl;
}

int main(int argc, char* argv[])
{
char name[100\];

cout<<"Enter Your Name:"; //cout -> Standard Output
cin>>name; //cin -> Standard Input

PrintGreeting(name);

return 1;
}

/* OUT PUT
Enter Your Name:nagvbt
Hello nagvbt
*/

2. C#

  • Input  - Console.WriteLine()
  • Output - Console.ReadLine()
// Print Greetings Program
// Basic Input/Output
namespace CSharpSample
{
class Program
{
static void PrintGreeting(char[] name)
{
Console.WriteLine("Hello "+ new string(name));
}

static int Main(string[] args)
{
char[] name;

Console.WriteLine("Enter Your Name:"); //Console.WriteLine() -> Standard Output
string sName = Console.ReadLine(); //Console.ReadLine() -> Standard Input
name = sName.ToCharArray();

PrintGreeting(name);

return 1;
}
}
}

/* * OUTPUT * *
Enter Your Name:
NBT
Hello NBT
* * * * * * * */

3. Java

Input - System.out.println()

Output - System.in.read()

import java.io.IOException;

class Program
{
public static void PrintGreeting(char[] name)
{
System.out.println("Hello "+ new String(name));
}

public static void main(String[] args)
{
char[] name;

System.out.print("Enter Your Name:"); //System.out.println -> Standard Output

String sName = "";
int tmp;
try
{
while((tmp = System.in.read ()) != 'n') // System.in.read -> Standard Input
{
char c = (char) tmp;
sName = sName + c;
}

}
catch (IOException e)
{
e.printStackTrace();
}

name = sName.toCharArray();
PrintGreeting(name);
}
}

/* OUTPUT
Enter Your Name:NBT
Hello NBT
*/

Part-3: C++, C#, Java Syntax Differences

· One min read

Comments, Methods, Class, objects Syntax Differences

Comments Same for C++, C#, Java

  1. Single line comments  - //
  2. Multi line comments

/ This is a a multiline comment /

Method/Function declarations

Same, except that in C# and in Java, function must always be part of a class, and must prefix with access specifier - public/private/protected

check main function for reference

Class declarations

Same but c# and Java does not require a semicolon after closing bracket '}'

_ C++ _

class myMath {
//Methods
public: int Add(int i, int j)
{
return i + j;
}
};

_ C#/Java _

 class myMath {
//Methods
public int Add(int i, int j)
{
return i + j;
}
}

Object declaration/creation C++

Object creation on Stack

myMath obj; //on stack
int result = obj.Add(1,2);

Object creation on Heap

myMath \*pobj = new myMath(); //on heap
int result = obj->Add(1,2);
delete pobj;

Java/C#

myMath obj = new myMath();
int result = obj.Add(1,2);

'Factory Method' Design Pattern using simple program

· One min read

Definition:

Creates an instance of several derived classes. or Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Program:

#include "iostream"
using namespace std;

class Product
{
public:
virtual void Show() = 0;
};

class ConcreteProductA : public Product
{
public:
virtual void Show()
{
cout<<"ConcreteProductA"<<endl;
}
};

class ConcreteProductB : public Product
{
public:
virtual void Show()
{
cout<<"ConcreteProductB"<<endl;
}
};

class Creator
{
public:
virtual Product* FactoryMethod() = 0;
};

class ConcreteCreatorA : public Creator
{
public:
ConcreteCreatorA() {}
virtual Product* FactoryMethod()
{
return new ConcreteProductA();
}
};

class ConcreteCreatorB : public Creator
{
public:
virtual Product* FactoryMethod()
{
return new ConcreteProductB();
}
};

void main()
{
Creator* creators[2];

creators[0] = new ConcreteCreatorA();
creators[1] = new ConcreteCreatorB();

for (int i=0; i < 2; i++) { Product* product = creators[i]->FactoryMethod();
cout<<"Created "<<Show();
}

getchar();
}

/*
OUT PUT
-------
Created
ConcreteProductA
Created
ConcreteProductB
*/

'Singleton' Design Pattern using simple program

· One min read

Definition: Ensure a class only has one instance and provide a global point of access to it.

Program:

#include "iostream"
using namespace std;

class Singleton
{
private:
static Singleton* instance;
Singleton() {}

public:
static Singleton* Instance()
{
if(instance == NULL)
{
instance = new Singleton();
}
return instance;
}

void Show()
{
cout&lt;&lt;"Singleton Class"&lt;&lt;endl;
}
};

Singleton* Singleton::instance = NULL;

int main()
{
Singleton* obj1 = Singleton::Instance();
obj1->Show();

Singleton* obj2 = Singleton::Instance();
obj2->Show();

getchar();

return 0;
}

/*
OUT PUT
-------
Singleton Class
Singleton Class
*/

‘AbstractFactory’ Design Pattern using simple program

· 2 min read

Definition: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

Program:


#include "iostream"
using namespace std;

// Abstract Factory pattern
class AbstractProductA
{
public:
virtual void Show() = 0;
};

class AbstractProductB
{
public:
virtual void Show() = 0;
};

class AbstractFactory
{
public:
virtual AbstractProductA* CreateProductA() = 0;
virtual AbstractProductB* CreateProductB() = 0;
};

class ProductA1 : public AbstractProductA
{
public:
virtual void Show()
{
cout<<"ProductA1 Show"<<endl;>
}
};

class ProductB1 : public AbstractProductB
{
public:
virtual void Show()
{
cout<<"ProductB1 Show"<<endl;>
}
};

class ProductA2 : public AbstractProductA
{
public:
virtual void Show()
{
cout<<"ProductA2 Show"<<endl;
}
};

class ProductB2 : public AbstractProductB
{
public:
virtual void Show()
{
cout<<"ProductB2 Show"<<endl;
}
};

class ConcreteFactory1 : public AbstractFactory
{
public:
virtual AbstractProductA* CreateProductA()
{
return new ProductA1();
}

virtual AbstractProductB* CreateProductB()
{
return new ProductB1();
}
};

class ConcreteFactory2 : public AbstractFactory
{
public:
virtual AbstractProductA* CreateProductA()
{
return new ProductA2();
}

virtual AbstractProductB* CreateProductB()
{
return new ProductB2();
}
};

class Client
{
private:
AbstractProductA* _abstractProductA;
AbstractProductB* _abstractProductB;

public:
Client(AbstractFactory\* factory)
{
_abstractProductB = factory->CreateProductB();
_abstractProductA = factory->CreateProductA();
}

void Run()
{
_abstractProductA->Show();
_abstractProductB->Show();

delete _abstractProductA;
delete _abstractProductB;
}
};

void main()
{
// Abstract factory #1
AbstractFactory* factory1 = new ConcreteFactory1();
Client* client1 = new Client(factory1);
client1->Run();

delete factory1;
delete client1;

// Abstract factory #2
AbstractFactory* factory2 = new ConcreteFactory2();
Client* client2 = new Client(factory2);
client2->Run();

delete factory2;
delete client2;

getchar();
}

/*
OUT PUT
-------
\[ProductA1\] Show
\[ProductB1\] Show
\[ProductA2\] Show
\[ProductB2\] Show
\*/