Preview

Gkjg

Good Essays
Open Document
Open Document
612 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Gkjg
SWEN.5132 -- Software Design Patterns

Assignment 2

FirstName: Sampath kumar reddy

LastName: Jonnalagadda

Grade:

Homework Questions:

1. The implementation of Prototype Pattern involves a creation of an object by another object. This capability is purely related with each programming language. We have given 3 examples by using 3 different languages.

a. In C#, which system function we have used to fulfill this purpose?

ANS:

To fulfill this purpose in C# we use the ‘object.MemberWiseClone()’ method.

b. Use online resource http://msdn.microsoft.com/en-us/library/default.aspx for following question: Please explain this function, including an example to illustrate the usage.

ANS:

With this function it creates a Shallow copy of the current object. MemberwiseClone() cannot be override or overridden, and is only one accessible through this class or a derived class. A shallow copy creates a new instance of the same type as the original object, and then creates copy of the non-static fields of the original object.

c. What is the name of the function in Java that performs the same purpose? Give an example.

ANS:

In most cases we use Clone () function in java to implement prototypes related programs . it can be illustrated an example .

import java.util.List; import java.util.LinkedList; import java.util.Iterator; public class CloningExample implements Cloneable { private LinkedList names = new LinkedList(); public CloningExample() { names.add("A"); names.add("B"); names.add("C"); } public String toString() { StringBuffer sb = new StringBuffer(); Iterator i = names.iterator(); while (i.hasNext()) { sb.append("\n\t" + i.next()); } return sb.toString(); } public Object clone() { try { return

You May Also Find These Documents Helpful

Related Topics