Question

In: Computer Science

Explain what composition is and how to use it.

Explain what composition is and how to use it.

Solutions

Expert Solution

Answer)
The composition is one of the many features of the object-oriented programming languages such as Java. The composition allows is to describe a class which references on or more than one objects which are in the other classes, for the instance variables. Composition allows us to have a has-a relationship between objects. Thus using this we can reuse the existing code, and also change the implementation of a class.
The composition is done using simple objects creation and then re-using the code in the other class in the current class. Thus using this the other class code is not affected and also also the code can be re-used in the current class. This should be used in the approach when the classes relationship depicts the has-a relationship and thus we should use composition rather than inheriting the entire class. Thus using this the client class code or anything does not need to be changed, and we can have the current class bear the change and also reuse the code.


Related Solutions

Use composition relationship. What is composition? You will find out what composition in object oriented programming....
Use composition relationship. What is composition? You will find out what composition in object oriented programming. Based on the bedroom package below please create your own classroom package. After completing entire package, you will write about your package specification in Readme.txt and also explain how you apply composition to your project. package Bedroom; public class Bedroom { private String name; private Wall wall1; private Wall wall2; private Wall wall3; private Wall wall4; private Ceiling ceiling; private Bed bed; private Lamp...
Use composition relationship. What is composition? You will find out what composition in object oriented programming....
Use composition relationship. What is composition? You will find out what composition in object oriented programming. Based on the bedroom package below please create your own classroom package. After completing entire package, you will write about your package specification in Readme.txt and also explain how you apply composition to your project. package Bedroom; public class Bedroom { private String name; private Wall wall1; private Wall wall2; private Wall wall3; private Wall wall4; private Ceiling ceiling; private Bed bed; private Lamp...
Explain what diversification is. How is diversification different from hedging? Mathematically, by looking at the composition...
Explain what diversification is. How is diversification different from hedging? Mathematically, by looking at the composition of portfolio variance, considering the relationship between beta and covariance, how does the effect of diversification change according to the change of the number of securities in the portfolio? Is this relationship between the reduction of portfolio variance and the increase of security numbers linear? If not, is it concave or convex? Why?
Explain how the composition of the column material varies from the bottom to the top of...
Explain how the composition of the column material varies from the bottom to the top of the distilling column.
1- Explain how lead inhibits heme synthesis. 2- Explain the difference in the chemical composition of...
1- Explain how lead inhibits heme synthesis. 2- Explain the difference in the chemical composition of hemosiderin and ferritin. 3- How is sideroblastic anemia confirmed by laboratory analysis? Explain your answer. 4- Differentiate primary and secondary hemochromatosis? 5- Explain the absorption and assimilation of non-heme iron into hemoglobin in the RBC.
In this text what are the two main principles of ethics? Explain the composition and role...
In this text what are the two main principles of ethics? Explain the composition and role of an ethics committee.
How does composition (by final use) of crude oil demand in the US and Canada differ...
How does composition (by final use) of crude oil demand in the US and Canada differ from many countries in the rest of the world that are less well developed and less motorized? Given your answer to above, how does this affect the refining sector in the US and Canada relative to many countries in the rest of the world?
Explain chromatography. What is it and how do I use it?
Explain chromatography. What is it and how do I use it?
Answer the following question in a composition of 10 to 20 sentences 1. Explain what is...
Answer the following question in a composition of 10 to 20 sentences 1. Explain what is missing from a focus on consumer research limited only to the United States, Canada, and Japan?
4. What was the composition of the purchase price? Why was this composition selected according to...
4. What was the composition of the purchase price? Why was this composition selected according to this case study? 5. Where are these companies today in terms of companies and also their stock prices? 6. How is the auto industry doing recently during the Covid-19 crisis? Be specific and Provide an example and your opinion
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT