Thursday, February 25, 2010

DESIGN PATTERNS

Write in detail about Design Patterns?

Design Patterns
A design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems.
Not all software patterns are design patterns. Design patterns deal specifically with problems at the level of software design. Other kinds of patterns, such as architectural patterns, describe problems and solutions that have alternative scopes. Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns. In order to achieve flexibility, design patterns usually introduce additional levels of indirection, which in some cases may complicate the resulting designs and hurt application performance.
By definition, a pattern must be programmed anew into each application that uses it. Since some authors see this as a step backward from software reuse as provided by components, researchers have worked to turn patterns into components. Meyer and Arnout claim a two-thirds success rate in componentizing the best-known patterns.
Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn't require specifics tied to a particular problem.
Structure
Design patterns are composed of several sections. Of particular interest are the Structure, Participants, and Collaboration sections. These sections describe a design motif: a prototypical micro-architecture that developers copy and adapt to their particular designs to solve the recurrent problem described by the design pattern. A micro-architecture is a set of program constituents (e.g., classes, methods...) and their relationships. Developers use the design pattern by introducing in their designs this prototypical micro-architecture, which means that micro-architectures in their designs will have structure and organization similar to the chosen design motif.
 In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. Common design patterns can be improved over time, making them more robust than ad-hoc designs.
 Domain specific patterns
 Efforts have also been made to codify design patterns in particular domains, including use of existing design patterns as well as domain specific design patterns. Examples include User Interface design patterns, Information Visualization and web design.
 The Pattern Languages of Programming Conference (annual, 1994—) proceedings include many examples of domain specific patterns.
 Classification
 Design Patterns originally grouped design patterns into the categories Creational Patterns, Structural Patterns, and Behavioral Patterns, and described them using the concepts of delegation, aggregation, and consultation. For further background on object-oriented design, see coupling and cohesion. For further background on object-oriented programming, see inheritance, interface, and polymorphism. Another classification has also introduced the notion of architectural design pattern which may be applied at the architecture level of the software such as the Model-View-Controller pattern












2:   Explain Design Patterns in Smalltalk MVC.?

The Model/View/Controller (MVC) triad of classes is used to build use interfaces in Smalltalk-80. Looking at the design patterns inside MVC should help you see the meaning of the term pattern.
 MVC consists of three kinds of objects. The Model is the application object, the View is its screen presentation, and the Controller defines the way the user interface reacts to user input. Before MVC, user interface designs tended to lump these objects together. MVC decouples them to increase flexibility and reuse.
MVC decouples views and models by establishing a subscribe/notify protocol between them. A view must ensure that its appearance reflects the state of the model. Whenever the model’s data changes, the model notifies views that depend on it. In response, each view gets an opportunity to update itself. This approach lets you attach multiple views to a model to provide different presentations. You can also create new views for a model without rewriting it.
Another feature of MVC is that views can be nested. For example, a control panel of buttons might be implemented as a complex view containing nested button views. The user interface for an object inspector can consist of nested views that may be reused in a debugger. MVC supports nested views with the Composite View class, a subclass of View. Composite View objects act just like View objects; a composite view can be used wherever a view can be used, but it also contains and manages nested views.
Again, we could think of this as a design that lets us treat a composite view just like we treat one of its components. But the design is applicable to a more general problem, which occurs whenever we want to group objects and treat the group like an individual object. It lets you create a class hierarchy in which some subclasses define primitive objects (e.g. button) and other classes define composite objects (Composite View) that assemble the primitives into more complex objects.
MVC also lets change the way a view responds to user input without changing its visual presentation. You might want to change the way it responds to the keyboard, for example, or have it use a pop-up menu instead of command keys. MVC encapsulates the response mechanism in a Controller object. There is a class hierarchy of controllers, making it easy to create a new controller as a variation on an existing one.
A view uses an instance of a Controller subclass to implement a particular response strategy, to implement a different strategy, simply replace the instance with a different kind of controller. It’s even possible to change a view’s controller at run-time to let the view change the way it responds to user input. For example, a view can be disabled so that it doesn’t accept input by giving it a controller that ignores input events.
The View-Controller relationship is an example of the Strategy design pattern. A Strategy is an object that represents an algorithm. It’s useful when you want to replace the algorithm either statically or dynamically, when you have a lot of variants of the algorithm, or when the algorithm has complex data structures that you want to encapsulate.
MVC uses other design patterns, such as Factory Method to specify the default controller class for a view and Decorator t add scrolling to a view. But the main relationships in MVC are given by the Observer, Composite, and Strategy design patterns

















3:   Explain about t Encapsulating Implementation Dependencies in supporting multiple window systems in designing a document editor?

Encapsulating Implementation Dependencies
The Window class encapsulates the things windows tend to do across window systems:
§  They provide operation for drawing basic geometric shapes.
§  They can iconify and deiconify themselves.
§  They can resize themselves.
§ The can (re)draw their contents ion demand, for example, when they are deiconified or when an overlapped and obscured portion of their screen shapes is exposed. 
The Window class must span the functionality of windows from different window systems. Lets considered two extreme philosophies: 
1. Intersection of functionalities: The window class interface provides only functionality that’s common to all window systems. The problem with this approach is that our window interface points up being only as powerful as the least capable windows system. We cannot take advantage of more advanced features even if most windows systems support them.
2. Union of functionality: Create an interface that incorporates the capabilities of all existing systems. The trouble here is that the resulting interface may well be huge and incoherent. Besides, we will have tio change it anytime a vendor revises it’s window system interface. 
Neither extreme is a viable solution, so our design will fall somewhere between the two. The window class will provide a convenient interface that supports the most popular windowing features. Because Lexi will deal with this class directly, the window class must also support the things Lexi knows about, namely, glyphs. That means Window’s interface must include a basic set of graphics operations that lets glyphs draw themselves in the window. The below table gives a sampling of the operations in the window class interface.










Responsibility Operations
Window Management Virtual void Redraw ( )
Virtual void Raise ( )
Virtual void Lower ( )
Virtual void Iconify ( )
Virtual void Deiconify ( )
. . .
Graphics Virtual void DrawLine (…)
Virtual void DrawRect (…)
Virtual void DrawPolygon (…)
Virtual void DrawText (…)
. . .

Window is an abstract class. Concrete subclasses of window support the different kinds of windows that users deal with. For example, application windows, icons, and warning dialogs are all windows, but they have somewhat different behaviors. So we can define subclasses like Application Window, Icon Window, and Dialog Window to capture these differences. The resulting class hierarchy gives applications like Lexi, a uniform and intuitive windowing abstraction, one that does not depend on any particular
Note that we have defined a window interface for Lexi to work with, where does the real platform-specific window come in? If we’re not implementing our own window system, then at some point our window abstraction must be implemented in terms of what the target window system provides. So where does that implementation live.

 One approach is to implement multiple versions of the window class and its subclasses, one version each for each windowing platform. We’d have to choose the version to use when we build Lexi for a given platform. But imagine the maintenance headaches we would have keeping track of multiple classes, all named ‘Window’ but each implemented on a different window system. Alternatively, we could create implementation-specific subclasses of each class in the window hierarchy and end up with another subclass explosion problem like the one we have when trying to add embellishments. Both of these alternatives have another drawback: neither gives us the flexibility to change the window system we use after we have compiled the program. So we will have to keep several different executables around as well.

 If we encapsulate a window system’s functionality in an object, then we can implement our window class and subclasses in terms of that object’s interface. Moreover if that interface can serve all the window systems we are interested in, then we wont have to change window or any of its subclasses to support different window systems. We can configure window objects to the window systems we want simply by passing them the right window system- encapsulating object. We can even configure the window at a run time.

4:   Discuss about design problems in Lexi’s design.?

Below are the seven problems in Lexi’s design:
§ Document structure: The choice of internal representation for the document affects nearly every aspect of Lexi’s design. All editing, formatting, displaying, and textual analysis will require traversing the representation. The way we organize this information will impact the design of the rest of the application.
§ Formatting: How does Lexi actually arrange text and graphics into lines and columns? What objects are responsible for carrying out different formatting policies? How do these policies interact with the document’s internal representation?
§ Embedding the user interface: Lexi’s user interface includes scroll bars, borders, and drop shadows that embellish the WYSIWYG document interface. Such embellishments are likely to change as Lexi’s user interface evolves. Hence it is important to be able to add and remove embellishments without affecting the rest of the application.
§ Supporting multiple look-and-feel standards: Lexi should adapt easily to different look-and-feel standards such as Motif and Presentation Manager (PM) without major modification.
§ Supporting multiple window systems: Different look-and-feel standards are usually implemented on different window systems. Lexi’s design should be as independent of the window system as possible.
§ User operations: Users control Lexi through various user interfaces, including buttons and pull-down menus. The functionality behind these interfaces is scattered throughout the objects in the application. The challenge here is to provide a uniform mechanism both for accessing this scattered functionality and for undoing its effects.
Spelling checking and hyphenation: How does Lexi support analytical operations such as checking for misspelled words and determining hyphenation points? How can we minimize the number of classes we have to modify to add a new analytical operation?





5:   Write a brief note on template method behavioral pattern.?

Template method behavioral pattern
The Template Design Pattern is perhaps one of the most widely used and useful design patterns. It is used to set up the outline or skeleton of an algorithm, leaving the details to specific implementations later. This way, subclasses can override parts of the algorithm without changing its overall structure.
This is particularly useful for separating the variant and the invariant behavior, minimizing the amount of code to be written. The invariant behavior is placed in the abstract class (template) and then any subclasses that inherit it can override the abstract methods and implement the specifics needed in that context. In the body of Template Method () (see UML diagram below), there are calls to operation1 () and operation2 (). What it is that operation1 () and operation2 () do are defined by the subclasses which override them.
A common example of this is when writing a program that will handle data using various sorting algorithms. The Abstract Class would have a method called Sort () (analogous to Template Method () -- the invariant behavior) which when called, would use the helper methods in the class, which are specified by any class that inherits from it. The helper methods in this case might be compare () (compares two objects and returns the one that is "higher") and sort Pass () (performs one iteration of a particular sorting algorithm) The interesting thing is that the usual control structure of object calls and relations is reversed. It is the parent class that calls the method in the subclass, a behavior which Richard E. Sweet refers to as the "Hollywood Principle" -- "Don't call us, we'll call you." The Template Design Pattern is of particular use in the Factory Design Pattern

VOC SORTED

abode-dwelling
accumen-sharp
adage-proverb
adhesive = tenacious
Admonish : usurp
admonish = cautious
Alienate : estrange
amiable-friendly
annihilate-destroy
Baffle : Frustrate
bahalf-on behalf of
behest-
belate = too late
belief : conviction
Brim : Border
cajole-coax
caprice - impulsive, whim
capricious-impulsive, whim, unpredictable
Cargo :freight
compunction-remorse
Concur :acquiesce
confiscate = appropriate
Covet : crave
discretion = prudence
disparity-unequality
Dispel : Scatter
dispel = dissipate
divertism-difference
divulge = reveal
Efface : obliterate
effluent-waste
efflugent –radiance
Emancipate : liberate
extricate-free from
fertile-fruitful
florid-ornate, showy
forbid-order
frieze-combine
furtive = stealthy
Hamper : obstruct
Heap : to pile
hover = linger
incentive : ----
inert: passive
Instigate : incite
lament : wail
latent = potential
latitude = scope
lethargy = stupor
mandatory-compulsory
meager(MEAGRE) : scanty
merry = gay
metamorphisis-transformation
mirth-laughter, merriment
misery : distress
momentary = transient
morbid-diseased, unhealthy
mortal-deadly
mortify-humilate
muse-ruminant, ponder
obstinate = stubborn
ordain-command
ordinance-appoint
ovation-applause
persistance-regret, refuse
premonition-fore warning
Pretension : pretentious
pretentious = ostentatious
profound-intense, deep
randy-sexually exciting
rapt-lively
remonstrance-protest, object
renounce = reject
revitance-repeat
scrutiny-done exam
solicit : urge
solicit = beechat
stiffle : sniths
subside : wane
to merit = to deserve
torpid-sluggish
tranquil = serene
turbid-muddy
veer : diverge
volume = quantity
whet-sharpen

Technical Questions in the second round --

---------------------------------------
[1] What are the current trends and areas of focus in IT.
My Ans. Talked about emerging trends of S/W Engg and ISO 9000 stuff
(gave vague ideas about them as I don't know much nor do I care
about these topics myself ;-)). Then mentioned the proliferation of O-O
methodologies and their usefulness in speeding up development process,
code re-usability, ease of maintenance, ease of bug-fixing.
Thirdly, mentioned the work going on in High-Speed N/w - FDDI, ATM,
Fast-Ethernet(100Mbps). Told whatever little I knew about ATM in
response to another question.
[2] What is a Micro-Kernel architecture.
My Ans. This is a developing area in OSs where instead of building the
kernel as a single monolithic structure starting from scratch, it is
built as a set of layers. The micro-kernel provides only the bare-bones
like Device-drivers, rudimentary filesystem support etc. on which,
depending on the intended area of application of the OS, it can be
customized to provide various higher level OS features like
Multiprocessing, IPC, etc.
Personal Questions in the second round --
--------------------------------------
1. Tell us about yourself, your background.
2. What does your father do currently.
3. Your performance in schooling, B.E.
4. Your +/- points.
5. Why do you think Wipro should take you.
6. What qualities do you have that make you a person suitable for going
into the IT industry (a corollary to the previous question).
7. What do your friends opine about you.
8. When do you think you will complete and be able to join.
9. How can you assure that you will join by that time.
10. Anything you want to know about us.
} /* End of for() */
a) Describe the memory management policies in Unix. How is paging
implemented? How page faults are handled?
Seems to be a favorite question for these chaps ---- Maurice Bach.
b) Write a macro in C for swapping two nibbles in a byte.
-Use the shift operators and be careful while defining temporary
variables( if you do so) as you have to write a macro. Otherwise
it is pretty simple.
c) What is the CPU-scheduling policy in Unix? - Round robin scheduling
with multilevel queues.
d) Diffrence between short term, long term and medium term scheduler.
-First two should be peaceful. The last one is also known as
swapper. (See Taenenbaum and/or Peterson)
e) Name various page-replacement policies. Which can be implemented
both with and without pre-emption? - see Peterson.
f) Describe the Sliding window protocol. What is it's advantage
over stop-and-wait? - Saves bandwidth. (Taenenbaum please)
2ND INTERVIEW (Both personal and technical interleaved)
a) Tell us something about yourself.
b) Aren't you going for higher studies abroad? Why?
c) Rank and CGPA. MSites do not have ranks but still they wanted to
know my approx position in my batch.
- Shady question. It is your job to convince them that for
MS, grades do not hold any meaning.
d) What is re-entrant code? --- Non-self modifying code. Can be
shared by many processes simultaneously. Gave e.g. of text-editors
like 'vi'.
Counter Q: But then no code modifies itself. What does 'non-self
modifying' mean? ---- I don't know for sure.
e) Diff between compilers and interpreters. Some fundaes about
how to link code in different files.
f) What would your friends tell us about you if we ask them?
Standard question for everyone.
Second interview: (fully personal) --- This was more interesting;-)
a) What did you feel about the ppt? --- wasn't very impressive
so gave some shady answer.
b) Have you heard of creativity? -- Ya.
Have you heard of Bernard Shaw? -- Ya.
(Then he rattled off some quote of BS regarding creativity)
What do you say? --- I put some shadiest fundaes regarding
visionaries and Leonardo da Vinci conceptualising Helicopters
in his time!
************************************************************************
NOTE: If you have been offered a job previously by any other company
after your BTech/BE or if you have even slightest of work experience
then make it a point to mention about it. It is a major plus point.
The interviewers will be definitely interested in knowing that some
other company also found you good enough to be selected.
************************************************************************
***************************************************************************
Personal Questions asked:
a)question
1. Tell me about urself, family background ..
2. Btech projects and M.S. projects
( spend more time here, even if u have not done much
workl; create a good impression)
3. Significant achievements in life.
( may be paper publications etc. )
4. Why did u leave ur previous company ( If u were working)
5. What do u expect from a company ?
( like how shd be the work environment etc. etc. )
************************************************************************
Technical Questions asked:
1. Explain your project
2. What are your areas of interest in Appli Prog
Personal Questions asked:
1. Introduce yourself
2. Why do you want to join INFOSYS
3. Do you have a passport
4. Have you taken GRE/TOEFL
5. Will you go abroad
6. Which prog is better - MTech or MS
7. Which prog do people prefer - MTech or MS
8. Why
Personal Questions asked:
a)Which other companies are you applying to?
in interview
a)question
my weakness, kinds of friendship, family details
b) response
They are impressed if one presents papers.
I have presented conference papers
in the national level.
Generally most of the companies asks about the project.
Regarding other technical questions, they put questions
on the courses I did.
B) Personal
-----------
i) Tell us something about yourself. (This has to be there)
ii) Strengths and weaknesses (This question also disguised in various
forms is always asked).
iii) Why should we hire you?
iv) Can you describe your project in short?
v) Why did you take 2-1/2 years to complete (My case!)
vi) If given the job when can you join. (Caution: Don't think that if
you give some unreal early deadlines they will offer you the job.
Always play safe and give a deadline by which time you are sure to
complete and join. Asking for extensions is the worst scenario).
Tips: Be confident, frank (But need not give away information which may weigh
against your case), free (use first names while addresing them, so be
alert when they introduce themselves) and cheerful (attend an interview
with a positive frame of mind). Remember you are IITians and you always
have an edge. That may sound arrogant, but its true.