Question

Please discuss the advantages and disadvantages of placing your classes within a single file or in...

Please discuss the advantages and disadvantages of placing your classes within a single file or in separate files? Also, explain what is an interface and How does an interface differs from an actual class?

Homework Answers

Answer #1

Advantages and disadvantages of placing your classes within a single file or in separate files?

Keeping all classes in a single file-

1. makes it easier to navigate in the Solution Explorer

2. follows the most common convention, making it easier for new developers to find their way around

3. offers a better granularity when working with version control systems, especially those where you have a locking checkout mechanism for editing files; you need to lock only the code for the class you are editing.

Keeping all classes in a seperate file-

1. Code reusability gets easy when we keep classes in seperate files

2. Break the giant source file and follow the rule: put shared class together and independent class seperate to seggregate code and for easy readability

3. unorganized-code will have difficulty to be maintained. Break the code into modules put them into separate class file, so the code can be reused and component are neat to be included at the right place.

What is Interface?

Like a class, an interface can have methods and variables, but the methods declared in an interface are by default abstract. It is used to achieve total abstraction.

Interfaces specify what a class must do and not how. It is the blueprint of the class.

Since languages does not support multiple inheritance in case of class, but by using interface it can achieve multiple inheritance .

It can also be used to achieve loose coupling.

Interface also represents the IS-A relationship.

How does an interface differs from an actual class?

1. An interface contains behaviors that a class implements but a class describes the attributes and behaviors of an object.

2. All the members of the interface are public by default, but variables and methods in a class can be declared using any access specifier(public, private, default, protected).

3. Interface cannot contain constructors, but class can contain constructor.

4. An Inteface cannot be instantiated i.e, objects cannot be created, on the other hand a class can be instantiated i.e, objects of a class can be created.

5. Inteface supports multiple inheritance, but class does not support.

6. Interface cannot inherit a class, but class can be inherit another class.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Explain how publicity differs from advertising. What are the advantages and disadvantages of publicity in a...
Explain how publicity differs from advertising. What are the advantages and disadvantages of publicity in a firm's promotion strategy?
Explain how publicity differs from advertising. What are the advantages and disadvantages of publicity in a...
Explain how publicity differs from advertising. What are the advantages and disadvantages of publicity in a firm's promotion strategy?
Discuss the advantages and disadvantages of at least 2 different sampling methods. Describe how researchers go...
Discuss the advantages and disadvantages of at least 2 different sampling methods. Describe how researchers go about selecting a sampling strategy. What role does the research question play in choosing the sample? What does it mean to have a representative sample and why is this vital to the outcome of the study?
Please Answer All Parts For each of the following transmission mediums, discuss and explain the advantages...
Please Answer All Parts For each of the following transmission mediums, discuss and explain the advantages and disadvantages of using each type for high speed data transmission (at least 10 Gbps). Take in to account factors such as noise, distance, and the type of medium: (a) Cat6A Cable (b) RG-6 Coax Cable (c) Single-mode fiber (d) Licensed Wireless (e) Unlicensed Wireless
Consider the following interface: interface Something {     boolean validate(int value); } Classes that implement “Something”...
Consider the following interface: interface Something {     boolean validate(int value); } Classes that implement “Something” interface can validate a specific value in different behaviors within some context. For example, this interface could be useful to program a candy dispenser machine to check whether the coin inserted is a valid coin such as a quarter with a diameter of 2.426 centimeters. Also, it could be useful to check if there is any candy available to dispense. Write two classes “Coin”...
Consider the following interface: interface Something {     boolean validate(int value); } Classes that implement “Something”...
Consider the following interface: interface Something {     boolean validate(int value); } Classes that implement “Something” interface can validate a specific value in different behaviors within some context. For example, this interface could be useful to program a candy dispenser machine to check whether the coin inserted is a valid coin such as a quarter with a diameter of 2.426 centimeters. Also, it could be useful to check if there is any candy available to dispense. Write two classes “Coin”...
(1) What are the advantages and disadvantages to using the Int data type rather than the...
(1) What are the advantages and disadvantages to using the Int data type rather than the bool data type to manipulate Boolean expressions? Why do students think the int data type is still used for Boolean expressions? (2) Discuss how C++ provides two-way selection through the if....else statement. Explain the syntax of this statement. Also, explain how the bool data type is used in C++ to manipulate Boolean expressions.
1.What is the difference between class/object? 2.Did you think about classes/objects around you since the last...
1.What is the difference between class/object? 2.Did you think about classes/objects around you since the last session? 3.What library do we need for processing file I/O? 4.What is the class for the input file stream? Give an example 5.What is the class for the output file stream? Give an example 6.Why do you want to use files instead of using input? 7.How do you read from a file? give an example 8.How do you write to a file? give an...
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods...
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods will make use of two text files. a. The first text file contains the names of cities. However, the first line of the file is a number specifying how many city names are contained within the file. For example, 5 Dallas Houston Austin Nacogdoches El Paso b. The second text file contains the distances between the cities in the file described above. This file...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT