We have been working very hard since 2009 to facilitate in your learning Read More. We can't keep up without your support. Donate Now.

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

Dear Students,
Below is a topic for GDB. Please make sure that your reply should be precise and to the point.
GDB will remain open for two consecutive working days from 23rd January to 24th January. Also make sure you post your GDB on time as No GDB will be accepted via email in any case.
Topic is as follows:

You have two classes, Class A and Class B. Being a programmer either you can implement Class B as nested class of Class A or you can inherit Class B from Class A. 

These are two ways to describe the relationship between classes. Discuses the situations in which, concept of public inheritance and nested class is more appropriate to use. Justify with solid reasons.


+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)


Views: 3097

Replies to This Discussion

ye kahin nai likha k ans 5-6 lines mein ho .... bs ye kaha hai k ans to the point and precised ho

CS201+GDB+Solution

See the attached file please

Attachments:
The concepts of class interface
Main article: Interface (computer science)
Every class implements (or realizes) an interface by providing structure (i.e. data and state) and method implementations (i.e. providing code that specifies how methods work). There is a distinction between the definition of an interface and the implementation of that interface. In most languages, this line is usually blurred, because a class declaration both defines and implements an interface. Some languages, however, provide features that help separate interface and implementation. For example, an abstract class can define an interface without providing implementation.
Languages that support class inheritance also allow classes to inherit interfaces from the classes that they are derived from. In languages that support access specifies, the interface of a class is considered to be the set of public members of the class, including both methods and attributes (via implicit getter and setter methods); any private members or internal data structures are not intended to be depended on by client code and thus are not part of the interface.
The object-oriented programming methodology is designed in such a way that the operations of any interface of a class are usually chosen to be independent of each other. It results in a layered design where clients of an interface use the methods declared in the interface. An interface places no requirements for clients to invoke the operations of one interface in any particular order. This approach has the benefit that client code can assume that the operations of an interface are available for use whenever the client holds a valid reference to the object.
Example
The buttons on the front of your television set, for example, are the interface between you and the electrical wiring on the other side of its plastic casing. You press the "power" button to toggle the television on and off. In this example, the television is the instance, each method is represented by a button, and all the buttons together comprise the interface. In its most common form, an interface is a specification of a group of related methods without any associated implementation of the methods.
Attributes and interface example: A television set has a myriad of attributes, such as size and whether it supports color, together comprise its structure. A class represents the full description of a television, including its attributes (structure) and buttons (interface).
Static method example: Getting the total number of televisions in existence could be a static method of the television class. This method is clearly associated with the class, yet is outside the domain of each individual instance of the class. Another example is a static method that finds a particular instance out of the set of all television objects

Any time you use public inheritance, you should make sure that any function
or object that expects a base class object will also be satisfied by a
derived class obejct as well, because the derived class object "is a" base
class object. If you're creating a class that "is a" base class (such as a
math student "is a" student), then inheritance is fine.
If your new class needs to utilize the behavior of the base class, but can't
actually be substituted for a base class object (even if just in one special
case), then layering (using a nested class) is a better approach. That's
referred to as the "is implemented in terms of" relationship.

plzzzzzzzz someone help ...:(

mujhy iski smjh ni a rahi ...

Solution:
The concepts of class interface
Main article: Interface (computer science)
Every class implements (or realizes) an interface by providing structure (i.e. data and state) and method implementations (i.e. providing code that specifies how methods work). There is a distinction between the definition of an interface and the implementation of that interface. In most languages, this line is usually blurred, because a class declaration both defines and implements an interface. Some languages, however, provide features that help separate interface and implementation. For example, an abstract class can define an interface without providing implementation.
Languages that support class inheritance also allow classes to inherit interfaces from the classes that they are derived from. In languages that support access specifies, the interface of a class is considered to be the set of public members of the class, including both methods and attributes (via implicit getter and setter methods); any private members or internal data structures are not intended to be depended on by client code and thus are not part of the interface.
The object-oriented programming methodology is designed in such a way that the operations of any interface of a class are usually chosen to be independent of each other. It results in a layered design where clients of an interface use the methods declared in the interface. An interface places no requirements for clients to invoke the operations of one interface in any particular order. This approach has the benefit that client code can assume that the operations of an interface are available for use whenever the client holds a valid reference to the object.
Example
The buttons on the front of your television set, for example, are the interface between you and the electrical wiring on the other side of its plastic casing. You press the "power" button to toggle the television on and off. In this example, the television is the instance, each method is represented by a button, and all the buttons together comprise the interface. In its most common form, an interface is a specification of a group of related methods without any associated implementation of the methods.
Attributes and interface example: A television set has a myriad of attributes, such as size and whether it supports color, together comprise its structure. A class represents the full description of a television, including its attributes (structure) and buttons (interface).
Static method example: Getting the total number of televisions in existence could be a static method of the television class. This method is clearly associated with the class, yet is outside the domain of each individual instance of the class. Another example is a static method that finds a particular instance out of the set of all television objects

You have two classes, Class A and Class B. Being a programmer either you can implement Class B as nested class of Class A or you can inherit Class B from Class A. 

 

These are two ways to describe the relationship between classes. Discuses the situations in which, concept of public inheritance and nested class is more appropriate to use. Justify with solid reasons.

 

When a sub class inherits from a base class, it includes the definitions of all the data and operations that the parent base class defines. In practice, inheritance is used in two major ways in C++: implementation inheritance, in which actual code is inherited by the child, and interface inheritance, in which only method names are inherited.

I typically prefer nesting classes. A class hierarchy where the subclasses depend on the implementation details of the super class can become inflexible. Forcing yourself to use the interface of the contained class keeps the design loosely-coupled. Polymorphism can be implemented using interfaces, which also tends to provide clearer code, I find. TOH, if you absolutely need access to the innards of the super class, and the subclass would inevitably have to change if the design of the super class did then inheritance is obviously the way to go. Others will no-doubt differ...

RSS

Looking For Something? Search Here

HELP SUPPORT

This is a member-supported website. Your contribution is greatly appreciated!

© 2020   Created by +M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service

.