Tag » Object Oriented Programming

Inversion of Control

Introduction

The following post is an excerpt of the sites cited under more reading section below.

When you have a class that uses methods or access properties of other objects it is easy to instantiate an object you need in the class and access those methods or properties but it is making the code coupled and hard to read, test and maintain. 467 kata lagi

Decoupling

Inheritance in C++ | program to build master table of data

#include<iostream>
#include<cstring>

using namespace std;
class base1
{
char dob,bg[3];
public:
char name;
void get1();
void disp1();
};

class base2
{
float ht,wt;
public:
void get2(); 508 kata lagi

Simple template function program in C++

#include<iostream>

using namespace std;
const int r=2,c=2;
template <class T>
class matrix
{
T m[r][c];
public:
void getval()
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{ 356 kata lagi

C++ program on simple exception handling (divide by zero)

#include<iostream>
using namespace std;

class excdemo
{
public:
double x,y;
void getval()
{
cout<<“\nEnter the val of x and y=”;
cin>>x>>y;

}
void divide()
{ 45 kata lagi

C++ Program to find Area of rectangle and the area of triangle using virtual function

#include<iostream>
using namespace std;
class complex
{
int r,i;
public:
complex()
{
r=0,i=0;
}
complex(int a,int b)
{
r=a,i=b;
}
void get();
void display();
friend complex operator+(complex c1,complex c2); 262 kata lagi

c++ program to Add, Subtract, Multiply, divide two complex numbers

#include<iostream>
using namespace std;
class complex
{
int r,i;
public:
complex()
{
r=0,i=0;
}
complex(int a,int b)
{
r=a,i=b;
}
void get();
void display();
friend complex operator+(complex c1,complex c2); 262 kata lagi

c++ Bookshop program

#include<iostream>
#include<cstring>
using namespace std;
class book
{
char *title,*author,*publisher;
int *stock,*price;
static int trans;
public:
book() /*constructor*/
{ trans++;
title=new char;
author=new char;
publisher=new char; 503 kata lagi