[转]Design Pattern Interview Questions

Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, template Pattern, MVC.

Updated with the explanation of Composite pattern, Decorator Pattern and Template Pattern.

Design Pattern Interview Question - Part 4

Introduction

(A) Can you explain bridge pattern?

(A) Can you explain composite pattern?

(I) Can you explain decorator pattern ?

(A) Can you explain Façade pattern?

(A) Can you explain chain of responsibility ( COR)?

(I) Can you explain proxy pattern?

(B) Can you explain template pattern?

(B)Can you explain MVC?

(A)What is aspect oriented programming?

(A)What is Inversion of control?

(I)What is OR mapping?

Other Interview question PDF's
 

Introduction
 

Again I repeat do not think you get an architecture position by reading interview questions. But yes there should be some kind of reference which will help you quickly revise what are the definition. Just by reading these answers you get to a position where you are aware of the fundamentals. But if you have not really worked you will surely fail with scenario based questions. So use this as a quick revision rather than a shot cutLately i have been writing and recording videos heavily on design patterns , UML and many architectural stuff you can visit http://www.questpond.com/ for design pattern and UML videos.

In case your are completely new to design patterns or you really do not want to read this complete  article do see our free design pattern Training and interview questions / answers videos.

You can read my previous articles on design patterns and UML in the below links:-

Part 1 – Design patterns Factory, Abstract factory, builder, prototype, shallow and deep copy, and singleton and command patterns

http://www.dotnetfunda.com/articles/article130.aspx    

Part 2 – Design patterns Interpreter, Iterator, Mediator, Memento and observer patterns

http://www.dotnetfunda.com/articles/article135.aspx   

Part 3 – Design patterns State, Stratergy, Visitor, Adapter and fly weight pattern 

http://www.dotnetfunda.com/articles/article137.aspx   

You can download by architecture interview question book from 

http://www.questpond.com/softArchi.zip.zip  

 

(A) Can you explain bridge pattern?
 

Bridge pattern helps to decouple abstraction from implementation. With this if the implementation changes it does not affect abstraction and vice versa. Consider the figure ‘Abstraction and Implementation’. The switch is the abstraction and the electronic equipments are the implementations. The switch can be applied to any electronic equipment, so the switch is an abstract thinking while the equipments are implementations.

 

Figure: - Abstraction and Implementation


Let’s try to code the same switch and equipment example. First thing is we segregate the implementation and abstraction in to two different classes. Figure ‘Implementation’ shows how we have made an interface ‘IEquipment’ with ‘Start()’ and ‘Stop()’ methods. We have implemented two equipments one is the refrigerator and the other is the bulb.
 

Figure :- Implementation


The second part is the abstraction. Switch is the abstraction in our example. It has a ‘SetEquipment’ method which sets the object. The ‘On’ method calls the ‘Start’ method of the equipment and the ‘off’ calls the ‘stop’.
 

Figure: - Abstraction


Finally we see the client code. You can see we have created the implementation objects and the abstraction objects separately. We can use them in an isolated manner.
 

Figure :- Client code using bridge


Figure :- You can find the C# code for bridge in the ‘BridgePattern’ folder.


(A) Can you explain composite pattern?
 

GOF definition :- A tree structure of simple and composite objects

Many times objects are organized in tree structure and developers have to understand the difference between leaf and branch objects. This makes the code more complex and can lead to errors. 

For example below is a simple object tree structure where the customer is the main object which has many address objects and every address object references lot of phone objects.

 

Figure: - General Process

Now let’s say you want to insert the complete object tree. The sample code will be something as shown below. The code loops through all the customers, all addresses inside the customer object and all phones inside the address objects. While this loop happens the respective update methods are called as shown in the below code snippet.

foreach (Customer objCust in objCustomers){objCust.UpDateCustomer(); foreach (Address oAdd in objCust.Addresses) {  oAdd.UpdateAddress(); }   foreach (Phone ophone in oAdd.Phones)   {     ophone.UpDatePhone();   }}

The problem with the above code is that the update vocabulary changes for each object. For customer its ‘UpdateCustomer’ , for address its ‘UpdateAddress’ and for phone it is ‘UpdatePhone’. In other words the main object and the contained leaf nodes are treated differently. This can lead to confusion and make your application error prone. 

The code can be cleaner and neat if we are able to treat the main and leaf object uniformly. You can see in the below code we have created an interface (IBusinessObject) which forces all the classes i.e. customer, address and phone to use a common interface. Due to the common interface all the object now have the method name as “Update”.

foreach (IBusinessObject ICust in objCustomers){ICust.Update();  foreach (IBusinessObject Iaddress in ((Customer)(ICust)).ChildObjects)   {     Iaddress.Update();foreach (IBusinessObject iphone in ((Address)(Iaddress)).ChildObjects)      {         iphone.Update();}   }}

In order to implement composite pattern first create an interface as shown in the below code snippet.

public interface IBusinessObject{        void Update();        bool isValid();        void Add(object o);       }

Force this interface across all the root objects and leaf / node objects as shown below.

public class Customer : IBusinessObject    {        private List<Address> _Addresses;        public IEnumerable<Address> ChildObjects        {            get            {                return (IEnumerable<Address>)_Addresses;            }        }        public void Add(object objAdd)        {            _Addresses.Add((Address) objAdd);        }        public void Update()        {                    }        public bool isValid()        {            return true;        }}

Force the implementation on the address object also.

public class Address : IBusinessObject    {        private List<Phone> _Phones;        public IEnumerable<Phone> ChildObjects        {            get            {                return (IEnumerable<Phone>)_Phones.ToList<object>();            }        }        public void Add(object objPhone)        {            _Phones.Add((Phone)objPhone);        }        public void Update()        {                   }        public bool isValid()        {            return true;        }          }

Force the implementation on the last node object i.e. phone.

public class Phone : IBusinessObject    {        public void Update()        {}        public bool isValid()        {return true;}        public void Add(object o)        {            // no implementaton        }      }    }


(I) Can you explain decorator pattern ?

Punch :- Decorator pattern adds dynamically stacked behavior thus helping us to change the behavior of the object on runtime.

There are situations where we would like to add dynamic stacked behavior to a class on runtime. The word stack is an important word to note. For instance consider the below situation where a hotel sells bread meals. They have four important products and the order can be placed using the below combination: -

  • Simple bread.
  • Bread with Chicken.
  • Bread with drinks
  • Bread with chicken and drinks.

In other words the order process behavior and the cost of the order changes on runtime depending on the type of the combination.

Figure: -

Below is a simple order with only bread which has two functions ‘prepare’ and ‘calculatecost’. We would like to add new products to this basic bread order dynamically on runtime depending on what the customer wants.

Below is a simple interface which every order will have i.e. Prepare and CalculateCost.

interface IOrder{string Prepare();double CalculateCost();}

The base product is the bread which implements the Iorder interface. We would like to add new products to the bread order and change the behavior of the complete order.

public class OrderBread : IOrder    {        public string Prepare()        {            string strPrepare="";            strPrepare = "Bake the bread in oven
";            strPrepare = strPrepare + "Serve the bread";            return strPrepare;        }        public double CalculateCost()        {            return 200.30;        }    }

We can alter the bread order dynamically using decorator pattern. To implement decorator pattern is a 5 steps process.

Step1:- Create a decorator class which aggregates the object / interface for which we need to add the behavior dynamically.

abstract class OrderDecorator : IOrder    {        protected IOrder Order;	  . . . . .	  . . . . .	  . . . . .    }

This decorator class will house the object and any method calls to the main object will first invoke all the housed objects and then the main object.

So for instance if you are calling the prepare method, this decorator class will invoke all the prepare methods of the housed object and then the final prepare method. You can see how the output changes when decorator comes in to picture.

Figure: -

Step 2: - The housed object/ interface pointer needs to be initialized. We can do the same by using various means for the sample below we will just expose a simple constructor and pass the object to the constructor to initialize the housed object.

abstract class OrderDecorator : IOrder    {        protected IOrder Order;	  public OrderDecorator(IOrder oOrder)        {            Order = oOrder;        }	  . . . . .    }

Step 3: - We will implement the Iorder interface and invoke the house object methods using the virtual methods. You can see we have created virtual methods which invoke the house object methods.

abstract class OrderDecorator : IOrder    {        protected IOrder Order;        public OrderDecorator(IOrder oOrder)        {            Order = oOrder;        }        public virtual string Prepare()        {            return Order.Prepare();        }        public virtual double CalculateCost()        {            return Order.CalculateCost();        }    }

Step 4: - We are done with the important step i.e. creating the decorator. Now we need to create dynamic behavior object which can be added to the decorator to change object behavior on runtime.

Below is a simple chicken order which can be added to the bread order to create a different order all together called as chicken + bread order. The chicken order is created by inheriting from the order decorator class.

Any call to this object first invokes custom functionality of order chicken and then invokes the housed object functionality. For instance you can see When prepare function is called it first called prepare chicken functionality and then invokes the prepare functionality of the housed object.

The calculate cost also adds the chicken cost and the invokes the housed order cost to sum up the total.

class OrderChicken : OrderDecorator    {        public OrderChicken(IOrder oOrder) : base(oOrder)        {        }                 public override string Prepare()        {            return base.Prepare() +  PrepareChicken();         }        private string PrepareChicken()        {            string strPrepare = "";            strPrepare = "
Grill the chicken
";            strPrepare = strPrepare + "Stuff in the bread";            return strPrepare;        }        public override double CalculateCost()        {            return base.CalculateCost() + 300.12;        }    }

Same way we can also prepare order drinks.

class OrderDrinks : OrderDecorator    {        public OrderDrinks(IOrder oOrder)            : base(oOrder)        {        }        public OrderDrinks()        {        }public override string Prepare()        {                        return base.Prepare() + PrepareDrinks();        }        private string PrepareDrinks()        {            string strPrepare = "";            strPrepare = "
Take the drink from freezer
";            strPrepare = strPrepare + "Serve in glass";            return strPrepare;        }        public override double CalculateCost()        {            return base.CalculateCost() + 10.12;        }    }

Step 5:- The final step is see the decorator pattern in action. So from the client side you can write something like this to create a bread order.

IOrder Order =new OrderBread();Console.WriteLine(Order.Prepare());Order.CalculateCost().ToString();

Below is how the output will be displayed for the above client call.

Order 1 :- Simple Bread menuBake the bread in ovenServe the bread200.3

If you wish to create the order with chicken, drink and bread, the below client code will help you with the same.

Order = new OrderDrinks(new OrderChicken(new OrderBread()));Order.Prepare();Order.CalculateCost().ToString();

For the above code below is the output which combines drinks + chicken + bread.

Order 2 :- Drinks with chicken and breadBake the bread in ovenServe the breadGrill the chickenStuff in the breadTake the drink from freezerServe in glass510.54

In other words you can now attach these behaviors to the main object and change the behavior of the object on runtime.

Below are different order combination we can generate , thus altering the behavior of the order dynamically.

Order 1 :- Simple Bread menuBake the bread in ovenServe the bread200.3Order 2 :- Drinks with chicken and breadBake the bread in ovenServe the breadGrill the chickenStuff in the breadTake the drink from freezerServe in glass510.54Order 3 :- Chicken with breadBake the bread in ovenServe the breadGrill the chickenStuff in the bread500.42Order 4 :- drink with simple breadBake the bread in ovenServe the breadTake the drink from freezerServe in glass210.42


(A) Can you explain Façade pattern?


Façade pattern sits on the top of group of subsystems and allows them to communicate in a unified manner.
 

Figure: - Façade and Subsystem


Figure ‘Order Façade’ shows a practical implementation of the same. In order to place an order we need to interact with product, payment and invoice classes. So order becomes a façade which unites product, payment and invoice classes.
 

Figure: - Order Facade


Figure ‘façade in action’ shows how class ‘clsorder’ unifies / uses ‘clsproduct’,’clsproduct’ and ‘clsInvoice’ to implement ‘PlaceOrder’ functionality.
 

Figure :- Façade in action


Note:- You can find the façade code in the ‘façade pattern’ folder.


(A) Can you explain chain of responsibility ( COR)?


Chain of responsibility is used when we have series of processing which will be handled by a series of handler logic. Let’s understand what that means. There are situations when a request is handled by series of handlers. So the request is taken up by the first handler, he either can handle part of it or can not, once done he passes to the next handler down the chain. This goes on until the proper handler takes it up and completes the processing.
 

Figure: - Concept of Chain of Responsibility


Let’s try to understand this concept by a small sample example. Consider figure ‘Sample example’ where we have some logic to be processed. So there are three series of processes which it will go through. So process 1 does some processing and passes the same to process 2. Process 2 does some kind of processing and passed the same to process 3 to complete the processing activity.
 

Figure: - Sample example


Figure ‘class diagram for COR’ the three process classes which inherit from the same abstract class. One of the important points to be noted is that every process points to the next process which will be called. So in the process class we have aggregated one more process object called as ‘objProcess’. Object ‘ObjProcess’ points to next process which should be called after this process is complete.
 

Figure: - Class diagram for COR
 

Now that we have defined our classes its time to call the classes in the client. So we create all the process objects for process1 , process2 and process3. Using the ‘setProcess’ method we define the link list of process objects. You can see we have set process2 as a link list to process1 and process2 to process3. Once this link list is established we run the process which in turn runs the process according to the defined link list.
 

Figure: - COR client code


Note :- You can get the code for the same in C# in ‘ChainOfResponsibility’ folder.


(I) Can you explain proxy pattern?


Proxy fundamentally is a class functioning as in interface which points towards the actual class which has data. This actual data can be a huge image or an object data which very large and can not be duplicated. So you can create multiple proxies and point towards the huge memory consuming object and perform operations. This avoids duplication of the object and thus saving memory. Proxies are references which points towards the actual object.

Figure ‘Proxy and actual object’ shows how we have created an interface which is implemented by the actual class. So the interface ‘IImageProxy’ forms the proxy and the class with implementation i.e. ‘clsActualImage’ class forms the actual object. You can see in the client code how the interface points towards the actual object.

Figure: - Proxy and actual object


The advantages of using proxy are security and avoiding duplicating objects which are of huge sizes. Rather than shipping the code we can ship the proxy, thus avoiding the need of installing the actual code at the client side. With only the proxy at the client end we ensure more security. Second point is when we have huge objects it can be very memory consuming to move to those large objects in a network or some other domain. So rather than moving those large objects we just move the proxy which leads to better performance.


Note :- You can get the proxy code in the ‘Proxy Pattern’ folder.
 

(B) Can you explain template pattern?
 

Template pattern is a behavioral pattern. Template pattern defines a main process template and this main process template has sub processes and the sequence in which the sub processes can be called. Later the sub processes of the main process can be altered to generate a different behavior.

Punch :- Template pattern is  used in scenarios where we want to create  extendable behaviors in generalization and specialization relationship.

For example below is a simple process to format data and load the same in to oracle. The data can come from various sources like files, SQL server etc. Irrespective from where the data comes, the overall general process is to load the data from the source, parse the data and then dump the same in to oracle.

Figure: - General Process

Now we can alter the general process to create a CSV file load process or SQL server load process by overriding ‘Load’ and ‘Parse’ sub process implementation.

Figure: - Template thought Process

You can see from the above figure how we have altered ‘Load’ and ‘Parse’ sub process to generate CSV file and SQL Server load process. The ‘Dump’ function and the sequence of how the sub processes are called are not altered in the child processes.

In order to implement template pattern we need to follow 4 important steps:-

  1. Create the template or the main process by creating a parent abstract class.
  2. Create the sub processes by defining abstract methods and functions.
  3. Create one method which defines the sequence of how the sub process methods will be called. This method should be defined as a normal method so that we child methods cannot override the same.
  4. Finally create the child classes who can go and alter the abstract methods or sub process to define new implementation.
public abstract class GeneralParser    {        protected abstract void Load();        protected abstract void Parse();        protected virtual void Dump()        {            Console.WriteLine("Dump data in to oracle");        }        public void Process()        {            Load();            Parse();            Dump();        }    }

The ‘SqlServerParser’ inherits from ‘GeneralParser’ and overrides the ‘Load’ and ‘Parse’ with SQL server implementation.

public class SqlServerParser : GeneralParser    {        protected override void Load()        {            Console.WriteLine("Connect to SQL Server");        }        protected override void Parse()        {            Console.WriteLine("Loop through the dataset");        }                }

The ‘FileParser’ inherits from General parser and overrides the ‘Load’ and ‘Parse’ methods with file specific implementation.

public class FileParser : GeneralParser    {        protected override void Load()        {            Console.WriteLine("Load the data from the file");        }        protected override void Parse()        {            Console.WriteLine("Parse the file data");        }         }

From the client you can now call both the parsers.

FileParser ObjFileParser = new FileParser();ObjFileParser.Process();Console.WriteLine("-----------------------");SqlServerParser ObjSqlParser = new SqlServerParser();ObjSqlParser.Process();Console.Read();

The outputs of both the parsers are shown below.

Load the data from the fileParse the file dataDump data in to oracle-----------------------Connect to SQL ServerLoop through the datasetDump data in to oracle

(B)Can you explain MVC?

MVC is a design approach to separate the GUI from the application model. The main motive behind MVC to separate the view of data from the actual processing of data. MVC stands for model, view and controller. So let’s define these three components and understand the MVC fundamental in a more precise format.

View: - View represents the look and feel of an application; in one line they represent the GUI of a system. So view gets data and put in cosmetic formatting before displaying on the UI. It can be HTML, JAVA Applets, Windows form, XSL etc.

Model: - They are responsible for processing the data, managing database connections, implementing business rules and querying database. It processes data and passes it on to the view with out worrying about the final cosmetic looks. Model gets requests from the controller and they notify the corresponding views regarding the data. In Microsoft technologies they are .NET DLL while in Java they are Java beans.

Controller: - Controllers accept user events like mouse click, button enter etc and reacts accordingly. Controllers get these events from views and they trigger events to change the model to update their state. Once models have updated their states they communicate the same to the corresponding views to refresh the display. In .NET technologies they the behind code while in Java it’s the Service method of the servlet.
 

Figure: - MVC in Action


So looking at the above figure we can say there are four main steps by which MVC works:-

1. User sends an event like keyboard, button click or enter event to the controller.
2. Controller sends this event to the model who in turn updates himself and sends the data to the controller.
3. Controller updates the corresponding view depending on the event.
4. This view is then viewed by the end user.

Note: - We have shown in the above figure how MVC will be implemented for .NET and JAVA. It’s not necessary that an architecture follows the same approach. What we mean to say is these are the common ways of doing it. For instance architecture can use an ISAPI filter rather than a behind code to implement the controller.
 

(A)What is aspect oriented programming?
 

Note :- This is something which is catching up the market so interviewer can ask you to see how you are in touch with the market. So probably this explanation can be quiet long but bear with me it is worth of it


We will try to make it as short as possible as this book is not a reference book. First, let us try to define it, which can probably save you during interview
 

Aspect-oriented software development is a new technology for separation of concerns (SOC) in software development. The techniques of AOSD make it possible to modularize crosscutting aspects of a system.


Ok that statement can save you for the first stage let us get down actually what is it. Let us revisit back how software development cycle evolved. 
When we look back at times of COBOL where we used to break the modules in small functionalities and use reusability to its maximum.

Then came the time when we talked in terms of Objects where things were clearer as software was modeled in terms of real life examples. It worked fine and until today is the most accepted way of implementing and organizing project. So why AOP?

Aspect oriented programming does not oppose OOP’s but rather supports it and make’s it more maintainable. So remove the logic from head the AOP is replacement of OOP. No its brother of OOP helping him to be better.

When we talk in terms of objects, it is an entity, which maps to real world domain. Object has attributes, which represent the state of object and define its behavior. By rule of object, oriented programming object should be stand alone and communicate with other objects using messages or defined interface. 

One object should not communicate with other object directly rather communicate through defined interfaces. Every object satisfies some “Concern” in relation to the system.
Twist: - What is Concern in AOP?
 

“A concern is a particular goal, concept, or area of interest”


There are mainly two types of concern from an object perspective:-
• Core / Main concerns, which it should satisfy and is his work.
• System concerns which are not related to business functionalities but software related concerns example audit trail, Error handling, Security etc.
Ok let us try to understand this principle by some actual example.
 

Figure: - Customer and Audit trail relationships


Above is a class diagram, which shows relationshipbetween two classes “ClsCustomer” and “ClsAuditTrail”. “ClsCustomer” class does inserting of new customers in to database and “ClsAuditTrail” does the auditing of what is changed in the customer class.

Now there are two concerns in this project:-
• Customer code should not exceed than 10 lengths (Business level concern) greater 
• All customer data, which is updated, should be audited. (System level concern)

Here goes the class code. If you see the ClsCustomer implementation in the update method, we have called the Audit trail implementation. If you really look from object-oriented point of view, we are doing something in customer class, which is supposed to be not his implementation: - Audit Trail logging. Thus, we have also broken down the rule of encapsulation. In short, the class not only handles his work but also some other work which is not his concern.

Ok now let us define crosscutting which is one of important aspects of AOP.
 

Twist: - What is cross cutting in AOP?


When one or many concerns span across module it is called as cross cutting. Example in our audit trail example we will probably need to audit trail for customer as well as supplier. So Audit trail can span across other objects also that is termed as cross cutting.

Below are both the classes actually implemented as per class diagram ‘Customer and Audit trail relationship’. If you see the “Update” method of the customer class, its doing both of the concerns that is checking for customer code length, and also maintaining the audit trail using the audit trail class.
 

Public Class ClsCustomer
Private pstrCustcode As String
Private pstrCustName As String
Public Property Code() As String
Get
Return pstrCustcode
End Get
Set(ByVal Value As String)
pstrCustcode = Value
End Set
End Property
Public Property CustomerName() As String
Get



Return pstrCustName End Get
Set(ByVal Value As String)

pstrCustName = Value
End Set
End Property
Public Function Update() As Boolean
‘ first / core concern
If pstrCustcode.Length() > 10 Then
Throw New Exception("Value can not be greater than 10")
End If
' usingthe customer audit trail to do auditing
‘ second concern / system concern
Dim pobjClsAuditTrail As New ClsAuditTrail
With pobjClsAuditTrail
.NewValue = "1001"
.OldValue = "1003"
.UserName = "shiv"
.Update()
End With
' then inserting the customer in database
End Function
End Class
Public Class ClsAuditTrail
Private pstrUserName As String
Private pstrOldValue As String
Private pstrNewValue As String
Private pdblLogTime As Double
Public Property UserName() As String

Return pstrUserName
End Get
Set(ByVal Value As String)
pstrUserName = Value
End Set
End Property
Public Property OldValue() As String
Get
Return pstrOldValue
End Get
Set(ByVal Value As String)
pstrOldValue = Value
End Set
End Property
Public Property NewValue() As String
Get
Return pstrNewValue
End Get
Set(ByVal Value As String)
pstrNewValue = Value


End Set
End Property
Public Property LogTime() As Double
Get
Return pdblLogTime
End Get
Set(ByVal Value As Double)
pdblLogTime = Value
End Set
End Property
Public Sub Update()
' do the logging activity here
End Sub
End Class

 

In short, the customer class is doing much activity. There is lot of tangling of code. So how do we overcome this problem...? Simple, separate the System level concern (Audit Trail) from the core level concern (Customer code check). This is achieved at this moment in .NET using attribute programming as shown in the below code snippet.


Here is the change to the customer class

Imports System.Reflection
Public Class ClsCustomer
Private pstrCustcode As String
Private pstrCustName As String
Public Property Code() As String
Get
Return pstrCustcode
End Get
Set(ByVal Value As String)

pstrCustcode = Value
End Set
End Property
Public Property CustomerName() As String
Get
Return pstrCustName
End Get
Set(ByVal Value As String)

pstrCustName = Value
End Set
End Property
<ClsAuditTrail("Shiv", "1001", "1003", 12)> _
Public Function Update() As Boolean
If pstrCustcode.Length() > 10 Then
Throw New Exception("Value can not be greater than 10")
End If
' usingthe customer audit trail to do auditing


‘th End Function

End Class
And here is the change to the audit trail class

Imports System.Reflection
<AttributeUsage(AttributeTargets.All)> _
Public Class ClsAuditTrail
Inherits Attribute
Private pstrUserName As String
Private pstrOldValue As String
Private pstrNewValue As String
Private pdblLogTime As Double
Public Property UserName() As String
Get
Return pstrUserName
End Get
Set(ByVal Value As String)
pstrUserName = Value
End Set
End Property
Public Property OldValue() As String
Get
Return pstrOldValue
End Get
Set(ByVal Value As String)
pstrOldValue = Value
End Set
End Property
Public Property NewValue() As String
Get
Return pstrNewValue
End Get
Set(ByVal Value As String)
pstrNewValue = Value
End Set
End Property
Public Property LogTime() As Double
Get
Return pdblLogTime
End Get
Set(ByVal Value As Double)
pdblLogTime = Value
End Set
End Property
Public Sub New(ByVal pstrUserName As String, _
ByVal pstrOldValue As String, _
ByVal pstrnewValue As String, _
ByVal plng As Long)
Update()
End Sub



In .NET AOP is currently support by using attribute programming. In JAVA you can use Annotation/JBOSS for implementing AOP.
 

(A)What is Inversion of control?


Inversion of control in acronym it’s also termed as Dependency Inversion Principle. Let’s say we have class A. Class A uses Class B. In short Class A depends on Class B. In short Class A can not be used with out Class B. Second Class B can not use Class A. In order to remove the dependency that Class A can not be used with out Class B we need to introduce an Interface I in between them. This is termed as IOC or DIP. So now both of the classes will communicate through this interface thus leading to loosely coupled and independent architecture. 
 

(I)What is OR mapping?


OR mapping is process in which we map classes to relation tables. Mapping places object attributes in one or more database fields. Ok let’s try understanding this with a simple example.

Figure: - OR mapper in action


In the above figure you can see on the right hand side we have physical customer table with three attributes Customer Code , CustomerName and Address. All these three attributes map the customer class defined in the right hand side. If the table has one to many relation ship similar mapping will be done on the class side also. Due the above mapping you can now handle save and retrieve more effectively. There are many OR mapping tools available in market which read your schema and create classes accordingly. It generates full persistence objects due to which you can minimize your code to a lot greater extent.

原文地址:https://www.cnblogs.com/yfdream/p/3511199.html