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: 3105

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

Latest Activity

Hacker updated their profile
9 minutes ago
Profile IconMaira Qurxam, Mr.Right, Kashif iqbal and 23 more joined Virtual University of Pakistan
20 minutes ago
+++!!zυηι кнαη(αм ¢у¢σ) liked Ali Fahad's discussion ECO401 ONLINE QUIZ 1 FALL 2020
1 hour ago
+++!!zυηι кнαη(αм ¢у¢σ) liked Virtual Educators Academy's discussion CS619 Final Projects (Python language) Discussions
1 hour ago
Imtiaz Waqar added a discussion to the group STA630 Research Methods
2 hours ago
Imtiaz Waqar joined +M.Tariq Malik's group
2 hours ago
Muhammad Fawad Hassan joined +M.Tariq Malik's group
2 hours ago
Maria commented on +M.Tariq Malik's group EDU101 Foundations of Education
2 hours ago
+ Faisal + replied to shifa arshad's discussion CS605 Assignment No 02 Fall 2020 Solution / Discussion Due Date: 10-dec-2020 in the group CS605 Software Engineering-II
2 hours ago
Maria joined +M.Tariq Malik's group
2 hours ago
Maria and SafeerZaidi are now friends
2 hours ago
SafeerZaidi liked Maria's profile
3 hours ago
Tasha Malik posted a status
"Bio 201 Assignment # 2 Solution https://youtu.be/Gowjc67WZ4c"
4 hours ago
Maria liked +M.Tariq Malik's profile
4 hours ago
Maria left a comment for +M.Tariq Malik
4 hours ago
Blessings posted a status
"Kya khbr k ab wo khan rehta hai...........................Khush rhe yar jhan rehta hai"
5 hours ago
SafeerZaidi liked +M.Tariq Malik's group PAK301 Pakistan Studies
5 hours ago
Virtual Educators Academy posted a discussion
5 hours ago
Virtual Educators Academy updated their profile
5 hours ago
☆ Tina Solangi ☆ updated their profile
6 hours ago

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

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

.