Skip to main content
fixed spelling and grammar
Source Link
doubleYou
  • 2.8k
  • 1
  • 13
  • 26

The above code is not maintainable and lacks reusability (assuming we could reuse the acceleration mechanism for the same track platform). TheThe following code applies the bridge pattern and separates the two different abstractions, train transport and acceleration.

The above code is not maintainable and lacks reusability (assuming we could reuse the acceleration mechanism for the same track platform). The following code applies bridge pattern and separates the two different abstractions, train transport and acceleration.

The above code is not maintainable and lacks reusability (assuming we could reuse the acceleration mechanism for the same track platform). The following code applies the bridge pattern and separates the two different abstractions, train transport and acceleration.

In OOP we use polymophismpolymorphism so an abstraction can have multiple implementations. Lets Let's look at the following example:

A new requirement introduced and needneeds to bring in the acceleration perspective of the trains, so change the code as below.

The above code is not maintainable and lack oflacks reusability (assuming we could reuse the acceleration machanismmechanism for the same track platform). Following The following code applyapplies bridge pattern and separateseparates the two different abstractions, train transport and acceleration.

In OOP we use polymophism so an abstraction can have multiple implementations. Lets look at the following example:

A new requirement introduced and need to bring in the acceleration perspective of the trains, so change the code as below.

The above code is not maintainable and lack of reusability (assuming we could reuse the acceleration machanism for the same track platform). Following code apply bridge pattern and separate the two different abstractions, train transport and acceleration.

In OOP we use polymorphism so an abstraction can have multiple implementations. Let's look at the following example:

A new requirement introduced and needs to bring in the acceleration perspective of the trains, so change the code as below.

The above code is not maintainable and lacks reusability (assuming we could reuse the acceleration mechanism for the same track platform). The following code applies bridge pattern and separates the two different abstractions, train transport and acceleration.

Spelling and comment syntax--attempted to make no changes to personal style, only changes for comprehension and clarity
Source Link

In OOP we use polymophism so an abstraction can have multiple implementations. Lets look at the following example -:

    public interface Train
    { 
        void move();
    }
    public class MonoRail:Train
    {
        public override void move()
        {
            //use one track;
        }
    }
    public class ElectricMonoRail:MonoRail
    {
        public override void move()
        {
            //use electircelectric engine on one track.
        }
    }
    public class DieselMonoRail: MonoRail
    {
        public override void move()
        {
            //use diesel engine on one track.
        }
    }
    public class Rail:Train
    {
        public override void move()
        {
            //use two tracks;
        }
    }
    public class ElectricRail:Rail
    {
        public override void move()
        {
            //use electircelectric engine on two tracks.
        }
    }
    public class DieselRail: Rail
    {
        public override void move()
        {
            //use diesel engine on two tracks.
        }
    }

The above code is not maintainable and lack of reusability (assuming we could reuse the acclerationacceleration machanism for the same track platform). Following code apply bridge pattern and seperateseparate the two different abstractions, train transport and acceleration.

public interface Train
{ 
    void move(Accelerable engine);
}
public interface Accelerable
{
    public void acclerateaccelerate();
}
public class MonoRail:Train
{
    public override void move(Accelerable engine)
    {
        //use one track;
        engine.accelerate();engine; //engine is pluggable (runtime dynamic)
    }
}
public class Rail:Train
{
    public override void move(Accelerable engine)
    {
        //use two tracks;
        engine.accelerate(); //engine is pluggable (runtime dynamic)
    }
}
public class ElectricEngine:Accelerable{//implementation*implementation code for acceleableaccelerable*/}
public class DieselEngine:Accelerable{//implementation*implementation code for acceleableaccelerable*/}

In OOP we use polymophism so an abstraction can have multiple implementations. Lets look at the following example -

    public interface Train
    { 
        void move();
    }
    public class MonoRail:Train
    {
        public override void move()
        {
            //use one track;
        }
    }
    public class ElectricMonoRail:MonoRail
    {
        public override void move()
        {
            //use electirc engine on one track.
        }
    }
    public class DieselMonoRail: MonoRail
    {
        public override void move()
        {
            //use diesel engine on one track.
        }
    }
    public class Rail:Train
    {
        public override void move()
        {
            //use two tracks;
        }
    }
    public class ElectricRail:Rail
    {
        public override void move()
        {
            //use electirc engine on two tracks.
        }
    }
    public class DieselRail: Rail
    {
        public override void move()
        {
            //use diesel engine on two tracks.
        }
    }

The above code is not maintainable and lack of reusability (assuming we could reuse the accleration machanism for the same track platform). Following code apply bridge pattern and seperate the two different abstractions, train transport and acceleration.

public interface Train
{ 
    void move(Accelerable engine);
}
public interface Accelerable
{
    public void acclerate();
}
public class MonoRail:Train
{
    public override void move(Accelerable engine)
    {
        //use one track;
        engine.accelerate();engine is pluggable (runtime dynamic)
    }
}
public class Rail:Train
{
    public override void move(Accelerable engine)
    {
        //use two tracks;
        engine.accelerate();//engine is pluggable (runtime dynamic)
    }
}
public class ElectricEngine:Accelerable{//implementation code for acceleable}
public class DieselEngine:Accelerable{//implementation code for acceleable}

In OOP we use polymophism so an abstraction can have multiple implementations. Lets look at the following example:

    public interface Train
    { 
        void move();
    }
    public class MonoRail:Train
    {
        public override void move()
        {
            //use one track;
        }
    }
    public class ElectricMonoRail:MonoRail
    {
        public override void move()
        {
            //use electric engine on one track.
        }
    }
    public class DieselMonoRail: MonoRail
    {
        public override void move()
        {
            //use diesel engine on one track.
        }
    }
    public class Rail:Train
    {
        public override void move()
        {
            //use two tracks;
        }
    }
    public class ElectricRail:Rail
    {
        public override void move()
        {
            //use electric engine on two tracks.
        }
    }
    public class DieselRail: Rail
    {
        public override void move()
        {
            //use diesel engine on two tracks.
        }
    }

The above code is not maintainable and lack of reusability (assuming we could reuse the acceleration machanism for the same track platform). Following code apply bridge pattern and separate the two different abstractions, train transport and acceleration.

public interface Train
{ 
    void move(Accelerable engine);
}
public interface Accelerable
{
    public void accelerate();
}
public class MonoRail:Train
{
    public override void move(Accelerable engine)
    {
        //use one track;
        engine.accelerate(); //engine is pluggable (runtime dynamic)
    }
}
public class Rail:Train
{
    public override void move(Accelerable engine)
    {
        //use two tracks;
        engine.accelerate(); //engine is pluggable (runtime dynamic)
    }
}
public class ElectricEngine:Accelerable{/*implementation code for accelerable*/}
public class DieselEngine:Accelerable{/*implementation code for accelerable*/}
Source Link
Thurein
  • 296
  • 1
  • 3
Loading