1 / 11

Interface Implementation Separation in C++

Interface Implementation Separation in C++. Dr.D.Jeya Mala Associate Professor Dept.of Computer Applications Thiagarajar College of Engineering Madurai -15. Tamil Nadu, India. Introduction. Interface Contains only the abstractions in terms of method declarations. Implementation

zulema
Download Presentation

Interface Implementation Separation in C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Interface Implementation Separation in C++ Dr.D.Jeya Mala Associate Professor Dept.of Computer Applications Thiagarajar College of Engineering Madurai -15. Tamil Nadu, India. This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  2. Introduction • Interface • Contains only the abstractions in terms of method declarations. • Implementation • Contains the implementation part of the method declarations. • purposes: • Reusability • Extensibility This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  3. Interface Implementation Separation in C++ • Interface of Rectangle Class - Stored as Rect.h class Rectangle { public: Rectangle(); void setData(float, float); void calcArea(void); float getWidth(void); float getLength(void); float getArea(void); ~Rectangle(); private: float width, length, area; }; This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  4. Implementation of Rectangle Class – Rect.cpp Rectangle :: Rectangle() { width=0; length=0; } void Rectangle::setData(float w, float l) { width = w; length = l; } void Rectangle::calcArea(void) { area = width * length; } This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  5. Program continues float Rectangle::getWidth(void) { return width; } float Rectangle::getLength(void) { return length; } float Rectangle::getArea(void) { return area; } Rectangle::~Rectangle() { } This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  6. Main program – Creation of Objects and Inovoking class members void main(void) { Rectangle box; // instance creation float wide, long; cout << "This program will calculate the area of a\n"; cout << "rectangle. What is the width? "; cin >> wide; cout << "What is the length? "; cin >> long; box.setData(wide, long); box.calcArea(); cout << "Here is the rectangle's data:\n"; cout << "width: " << box.getWidth() << endl; cout << "length: " << box.getLength() << endl; cout << "area: " << box.getArea() << endl; } This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  7. Program Output This program will calculate the area of a rectangle. What is the width? 10 [Enter] What is the length? 5 [Enter] Here is the rectangle's data: width: 10 length: 5 area: 50 This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  8. Summary • The discussion focused on • OO Concepts • Creation of Classes and Objects • Implementation of Abstraction and Encapsulation • Interface and Implementation Separation in C++ This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  9. Quiz • A Class is a _____________ entity; whereas an Object is a __________ entity. • List the OO Concepts. • Elimination of inessential properties and grouping of essential ones is _________ • A Class contains __________ and _____________ • Binding of Member Data and Member Functions is ______________ • When object is created for a class _________ will be shared and _________ will be uniquely created. • Why interface and implementation separation is important? • Apply Abstraction and Encapsulation to a ‘student’ class that has attributes as regno, name which is a character array, marks in five subjects and methods to get, set and calculating grade with their interface and implementation separation. This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  10. Works Cited • BjarneStroustrup, “The C++ Programming Language”, 3rd Edition and Special Edition, Addison Wesley, 2000 • Robert Laffore, “Object Oriented Programming using C++”, 4th Edition, Sams Publishing, 2002. • Stanley Lippman, “C++ Primer”, 4th Edition, Pearson Education, 2007. • Yashavant P. Kanetkar, “Let Us C++”, BPB Publications, 2007. • D.Jeya Mala, S.Geetha, “Object Oriented Analysis and Design using UML”, Tata McGraw Hill Publishers, 2013. This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.

  11. Thank You

More Related