Skip to content

Commit 9be9f9f

Browse files
committed
these are the initial repos that are to be loaded to the github java repository
1 parent 48fa551 commit 9be9f9f

File tree

48 files changed

+8483
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+8483
-0
lines changed

changelog.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### why are you here?
2+
3+
this page was added on 2 01 2018 so wishing everyone a good luck . we are hosting the rough codes that we have been doing through the days and still keeping up to the cycle of newer horizons in th e near future we dream big so we expect you to do so with us
4+
5+
###what will i get here ?
6+
7+
these are the data- structures and programs developed by the use of famous libraries of the time which have been tested over time to be error free and the best part is they are free to use.
8+
9+
###what are the libraries used ??
10+
11+
these codes have used several of the standard libraries , gnu scientific library , poco native libraries , boost static headers and also uses the dynamic libraries provided by them . there is also use of the proven datastructures as listed by the libraries themselves
12+
13+
##how to go about ??
14+
15+
every folder that has some code in it , has a modify.md file on for the convenience of tracking contributions and timeline ... if you find something fishy do report us at issues of this git repository we would get back to you as soon as possible and maybe resolve your issues over a cup of coffee
16+
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <iostream>
2+
3+
typedef int Coordinate;
4+
typedef int Dimension;
5+
6+
// Desired interface
7+
8+
using namespace std;
9+
class Rectangle
10+
{
11+
public:
12+
virtual void draw() = 0;
13+
};
14+
15+
// Legacy component
16+
class LegacyRectangle
17+
{
18+
public:
19+
LegacyRectangle(Coordinate x1, Coordinate y1, Coordinate x2, Coordinate y2)
20+
{
21+
x1_ = x1;
22+
y1_ = y1;
23+
x2_ = x2;
24+
y2_ = y2;
25+
cout << "LegacyRectangle: create. (" << x1_ << "," << y1_ << ") => ("
26+
<< x2_ << "," << y2_ << ")" << endl;
27+
}
28+
void oldDraw()
29+
{
30+
cout << "LegacyRectangle: oldDraw. (" << x1_ << "," << y1_ <<
31+
") => (" << x2_ << "," << y2_ << ")" << endl;
32+
}
33+
private:
34+
Coordinate x1_;
35+
Coordinate y1_;
36+
Coordinate x2_;
37+
Coordinate y2_;
38+
};
39+
40+
// Adapter wrapper
41+
class RectangleAdapter: public Rectangle, private LegacyRectangle
42+
{
43+
public:
44+
RectangleAdapter(Coordinate x, Coordinate y, Dimension w, Dimension h):
45+
LegacyRectangle(x, y, x + w, y + h)
46+
{
47+
cout << "RectangleAdapter: create. (" << x << "," << y <<
48+
"), width = " << w << ", height = " << h << endl;
49+
}
50+
virtual void draw()
51+
{
52+
cout << "RectangleAdapter: draw." << endl;
53+
oldDraw();
54+
}
55+
};
56+
57+
int main()
58+
{
59+
Rectangle *r = new RectangleAdapter(120, 200, 60, 40);
60+
r->draw();
61+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
this is the first design pattern ever implemented by a cs coder
2+
3+
remember the adapter pattern can only be implemented when multiple inheritance is allowed
4+
5+
the class is to get the correct data interface between existing and new code as a adapter between the informations to be exchanged.
6+
7+
output::
8+
---------
9+
10+
LegacyRectangle: create. (120,200) => (180,240)
11+
RectangleAdapter: create. (120,200), width = 60, height = 40
12+
RectangleAdapter: draw.
13+
LegacyRectangle: oldDraw. (120,200) => (180,240)
14+
15+
16+
17+
the pages that are best suited for learning
18+
19+
refactoring.guru
20+
21+
sourcemaking.com
22+
23+
24+
downside
25+
---------
26+
27+
Increases overall code complexity by creating additional classes.
28+
29+
30+
31+
Bridge is designed up-front to let the abstraction and the implementation vary independently. Adapter is retrofitted to make unrelated classes work together. Adapter makes things work after they're designed; Bridge makes them work before they are.
32+
33+
34+
Adapter provides a different interface to its subject. Proxy provides the same interface. Decorator provides an enhanced interface.
35+
36+
37+
Adapter is meant to change the interface of an existing object. Decorator enhances another object without changing its interface. Decorator is thus more transparent to the application than an adapter is. As a consequence, Decorator supports recursive composition, which isn't possible with pure Adapters.
38+
39+
40+
Facade defines a new interface, whereas Adapter reuses an old interface. Remember that Adapter makes two existing interfaces work together as opposed to defining an entirely new one.
41+
42+
State, Strategy, Bridge (and to some degree Adapter) have similar solution structures. They all share elements of the "handle/body" idiom. They differ in intent - that is, they solve different problems.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include <iostream>
2+
#include <iomanip>
3+
#include <string>
4+
5+
using namespace std;
6+
class TimeImp {
7+
public:
8+
TimeImp(int hr, int min) {
9+
hr_ = hr;
10+
min_ = min;
11+
}
12+
virtual void tell() {
13+
cout << "time is " << setw(2) << setfill(48) << hr_ << min_ << endl;
14+
}
15+
protected:
16+
int hr_, min_;
17+
};
18+
19+
class CivilianTimeImp: public TimeImp {
20+
public:
21+
CivilianTimeImp(int hr, int min, int pm): TimeImp(hr, min) {
22+
if (pm)
23+
strcpy(whichM_, " PM");
24+
else
25+
strcpy(whichM_, " AM");
26+
}
27+
28+
/* virtual */
29+
void tell() {
30+
cout << "time is " << hr_ << ":" << min_ << whichM_ << endl;
31+
}
32+
protected:
33+
char whichM_[4];
34+
};
35+
36+
class ZuluTimeImp: public TimeImp {
37+
public:
38+
ZuluTimeImp(int hr, int min, int zone): TimeImp(hr, min) {
39+
if (zone == 5)
40+
strcpy(zone_, " Eastern Standard Time");
41+
else if (zone == 6)
42+
strcpy(zone_, " Central Standard Time");
43+
}
44+
45+
/* virtual */
46+
void tell() {
47+
cout << "time is " << setw(2) << setfill(48) << hr_ << min_ << zone_ <<
48+
endl;
49+
}
50+
protected:
51+
char zone_[30];
52+
};
53+
54+
class Time {
55+
public:
56+
Time(){}
57+
Time(int hr, int min) {
58+
imp_ = new TimeImp(hr, min);
59+
}
60+
virtual void tell() {
61+
imp_->tell();
62+
}
63+
protected:
64+
TimeImp *imp_;
65+
};
66+
67+
class CivilianTime: public Time {
68+
public:
69+
CivilianTime(int hr, int min, int pm) {
70+
imp_ = new CivilianTimeImp(hr, min, pm);
71+
}
72+
};
73+
74+
class ZuluTime: public Time {
75+
public:
76+
ZuluTime(int hr, int min, int zone) {
77+
imp_ = new ZuluTimeImp(hr, min, zone);
78+
}
79+
};
80+
81+
int main() {
82+
Time *times[3];
83+
times[0] = new Time(14, 30);
84+
times[1] = new CivilianTime(2, 30, 1);
85+
times[2] = new ZuluTime(14, 30, 6);
86+
for (int i = 0; i < 3; i++)
87+
times[i]->tell();
88+
}
57.9 KB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bridge is a structural design pattern that lets you split a giant class or a set of closely related classes into two separate hierarchies, abstraction and implementation, which can be developed independently of each other.
2+
3+
4+
The motivation is to decouple the Time interface from the Time implementation, while still allowing the abstraction and the realization to each be modelled with their own inheritance hierarchy. The implementation classes below are straight-forward. The interface classes are a little more subtle. Routinely, a Bridge pattern interface hierarchy "has a" implementation class. Here the interface base class "has a" a pointer to the implementation base class, and each class in the interface hierarchy is responsible for populating the base class pointer with the correct concrete implementation class. Then all requests from the client are simply delegated by the interface class to the encapsulated implementation class.
5+
7.71 KB
Loading
13.5 KB
Loading
42.7 KB
Loading

0 commit comments

Comments
 (0)