Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

need thoughts on my interview question - .net, c#

Tags:

c#

.net

One of the questions I was asked was that I have a database table with following columns

pid - unique identifier
orderid - varchar(20)
documentid - int 
documentpath - varchar(250)
currentLocation - varchar(250)
newlocation - varchar(250)
status - varchar(15)

I have to write a c# app to move the files from currentlocation to newlocation and update status column as either 'SUCCESS' or 'FAILURE'.

This was my answer

  1. Create a List of all the records using linq

  2. Create a command object which would be perform moving files

  3. using foreach, invoke a delegate to move the files -

  4. use endinvoke to capture any exception and update the db accordingly

I was told that command pattern and delegate did not fit the bill here - i was aksed to think and implement a more favorable GoF pattern.

Not sure what they were looking for - In this day and age, do candidates keep a lot of info on head as one always has google to find any answer and come up with solution.

like image 986
uno Avatar asked Mar 25 '10 02:03

uno


People also ask

What are all the C# important topics for an experienced interview?

You should thoroughly practice control statements, arrays, functions, object classes, properties, inheritance, abstraction, polymorphism, CLR, CLS, CTS, and strings exception handling to ace C# interview questions and answers for experienced professionals.

What should I know about C# interview?

You will need to have some understanding of concepts like encapsulation, polymorphism, abstraction, inheritance, interfaces, etc., as C# is an object-oriented programming language. Basic knowledge of C, C++, or Java so you can understand the syntax of C# better.


1 Answers

I sort of agree with Aaronaught's comment above. For a problem like this, sometimes you can overthink it and try to do something more than you actually need to do.

That said, the one GoF pattern that came to mind was "Iterator." In your first statement, you said you would read all the records into a List. The one thing that could be problematic with that is if you had millions of these records. You'd probably want to process them in a more successive fashion, rather than reading the entire list into memory. The Iterator pattern would give you the ability to iterate over the list without having to know the underlying (database) storage/retrieval mechanism. The underlying implementation of the iterator could retrieve one, ten, or a hundred records at a time, and dole them out to the business logic upon request. This would provide some testing benefit as well, because you could test your other "business" logic using a different type of underlying storage (e.g. in-memory list), so that your unit tests would be independent from the database.

like image 159
Andy White Avatar answered Sep 21 '22 13:09

Andy White