Showing posts with label interview. Show all posts
Showing posts with label interview. Show all posts

Wednesday, February 26, 2014

.Net Entity Framework and DAL

This old post demonstrates some very interesting thoughts about DAL and Entity Framework, and discussed the design pattern (pros and cons) in an architecture point of view. At the last of this post, a ppt is embedded. http://www.wadewegner.com/2009/06/architecting-your-data-access-layer-with-the-entity-framework/
Here are some highlights and my understanding:
·         Use EF as DAL  This is still a good option to replace the CRUD. See my OpsLog comments below about EF.
·         Full Encapsulation of the Entity Framework.  This is the ideal solution but we probably won’t get to the complexity. It reduces coupling and make application testable.
·         Partial Encapsulation of the Entity Framework.  The author didn’t give an example, but I have some in EGMAN.  EGMAN uses MVC and MVVM (MVVM Model-View ViewModel is similar to MVC, Model-View Controller).  I used EF to map db to model (M in MVC), but sometimes lost the flexibility to add custom attribute and data access logic. I adopted MVVM, which use VM to replace C, and VM is the encapsulation of EF that extract data from the Model. 

Monday, November 16, 2009

c# revert a LinkedList

void ReverseLinkedList(LinkedList ls)
{
if ( ls == null || ls.Head == null )
return;
ListNode head = ls.Head;
ListNode current = head.Next;
while(current!=null)
{
ListNode tmp = current;
current = current.Next;
tmp.Next = head;
head = tmp;
}
ls.Head.Next = null;
ls.Head = head;
}

c# merge sort algorithm implementation

        private int[] MergeSort(int[] a)
{
if ( a.Length == 1)
return a;
int middle = a.Length / 2;
int[] left = new int[middle];
for (int i = 0 ; i < middle ; i ++)
{
left[ i ] = a[ i ];
}
int[] right = new int[a.Length - middle];
for( int i = 0; i < a.Length - middle; i++ )
{
right[i] = a[i+middle];
}
left = MergeSort( left );
right = MergeSort( right );

int leftptr = 0;
int rightptr = 0;

int[] sorted = new int[a.Length];
for(int k = 0 ; k < a.Length; k++)
{
if ( rightptr == right.Length || ((leftptr < left.Length ) && (left[leftptr] <= right[rightptr])))
{
sorted[ k ] = left[ leftptr ];
leftptr++;
}
else if( leftptr == left.Length || ((rightptr < right.Length ) && (right[rightptr] <= left[leftptr] )))
{
sorted[k] = right[rightptr];
rightptr++;
}
}
return sorted;
}

c# Quick Sort Algorithm Implementation

private void QuickSort( int[] a, int left, int right ) 
        { 
            if( a == null ) 
                return; 
            int i = left; 
            int j = right; 
            int pivot = a[( left + right ) / 2]; 
            while( i <= j ) 
            { 
                while( a[i] < pivot ) 
                    i++; 
                while( a[j] > pivot ) 
                    j--; 
                if( i <= j ) 
                { 
                    int tmp = a[i]; 
                    a[i++] = a[j]; 
                    a[j--] = tmp; 
                } 
            } 
            if( j > left ) 
            { 
                QuickSort( a, left, j ); 
            } 
            if( i < right ) 
            { 
                QuickSort( a, i, right ); 
            } 
        }

c# insert sort algorithm implementation

        private void insert_sort( int[] s )
{
for( int k = 1; k < s.Length ; k++ )
{
int value = s[k];
for( int i = 0; i <= k - 1; i++ )
{
if( value < s[i] )
{
for( int j = k - 1; j >= i; j-- )
s[j + 1] = s[j];
s[i] = value;
break;
}
}
}
}

Saturday, October 31, 2009

键盘上的符号发音

~
tilde (sounds like til-da); be prepared to explain to computer-illiterate people saying "you know, the wave-shaped thingy"

!
exclamation; commonly read as bang in case of #!/bin/sh

@
at

#
pound; but commonly read as shee in case of #!/bin/sh, not sure why

$
dollar

%
percent

^
caret; not many people know this word so be prepared to say "no, not carrot; it's the character above 6, an arrow pointing up"

&
ampersand

*
star; some read asterisk

(
opening parenthesis (some may shorten it saying paren)

)
closing parenthesis

_
underscore; once I heard people say underbar

+
plus

-
minus; as symbol before arguments in commands, some people including me read dash, easier to say one syllable

=
equals

`
backtick or backquote

{
opening brace

}
closing brace

[
opening bracket

]
closing bracket

|
pipe or vertical bar

\
backslash; be prepared to explain to some computer-illiterate people

:
colon

;
semicolon

"
double quote

'
single quote

<
less than; some may read left angle bracket

>
greater than

,
comma

.
dot; period if in English text

?
question mark

/
slash or forward slash; some computer-illiterate people may be confused about / and \

space

(), [] and {}
may also be called brackets in general. In that case, they specifically call [] square brackets and {} curly brackets. I never like this. Open and Closing may also be called left and right.