Define the terms coupling and cohesion. Do we want more, or less, of each of the
ID: 3826951 • Letter: D
Question
Define the terms coupling and cohesion. Do we want more, or less, of each of them, and why? On the internet, you'll read many experts recommend we "program to an interface." Why is it a good idea to first create an interface for our supplier code (give at least two reasons)? Sometimes as we program we throw exceptions, at other times, we catch them. Describe scenarios under which each is appropriate, giving real-world scenarios as examples. What is the advantage of serialization over standard ways we've read and written simple text files in the past? What limitations are there, on what objects can be serialized? Why is the concept of version numbering so important with serialization? e. What are the methods offered by an iterator, and what is the purpose of each one? If we want our iterator-including collections to support the for/each loop, what additional step must we take?Explanation / Answer
Answer a.Coupling:
An indication of the strength of interconnections between program units is also
known as Coupling.
It can also be measured of the extent to which an entity depends on other entities.
If Coupling would be more all other modules will require to change if they are dependent
on it. which can take time and efforts.
If Coupling would be Less it can take less time to modify as there will no dependency or
less dependency between them.
Cohesion:
Cohesion is an Measure of how well module fits together.
Thus, cohesion measures the strength of relationship between pieces of functionality within
a given module.
High cohesion would then mean that the class is focused on what it should be doing, i.e.
only methods relating to the intention of the class.
Low cohesion would mean that the class does a great variety of actions and is not focused
on what it should do
Answer b.
Program to an Interface is important as it can make class loosely coupled with the help of
Interface. For Example if you have ilogging file for logging purpose in the class and for any
of the purpose if you would like to make changes in it. It will be tedious as u will required to
change whole class file. So Better way we have an Interface Ilogger which has file name
ilogging which is implemented in the class.
Secondly, because if you later decide to change it use a different implementation, you have
a lot more work undoing all the unnecessary bindings.I.e. program to/bind to things without
implementation details.
Answer c.
Let us take an real life example of Dishwasher. if Dishwasher does'nt work properly and just throw
soap outside of it so we call the company software engineer who underestand exception
generated on the screen and he know the solution to it. So in this scenario exception handled
after it occured.
Second Example is Software Avoiding car crash. If another car was stoped in the road software
slow down the car but cannot avoid completely avoid the crash. Here we can underestand that
developers were able to find the logic of slow the car down to atleast minimum effect of the problem.
Answer d.
The advantages of serialization are:
It is easy to use and can be customized.
The serialized stream can be encrypted, authenticated and compressed, supporting the needs of
secure Java computing.
To serialize an object means to convert its state to a byte stream so that the byte stream can be
reverted back into a copy of the object. A Java object is serializable if its class or any of its superclasses
implements either the java.io.Serializable interface or its subinterface, java.io.Externalizable.
A serialVersionUID is very important as it used for purpose of deserialization. It checks the sender
and reciever of a serialized object have loaded object of class which should be serialized.
If serialVersionUID it does'nt matches with sender and reciever it will generate an InvalidClassException.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.