Tags » Decorator

A Weird (and Mostly Impractical) Way to Do Multi-Line "Lambdas" in Python

Some of you who follow me may have noticed a tendency of mine to “hack” programming languages more than really use them (other than reflection via annotations in languages such as Java; I hate that stuff), and today is no different. 1,690 more words

Python

Chrome Bathroom Accessories

One thing we said no to at our World of Style appointment was the option for Porter Davis to add the bathroom accessories. They had a small range to choose from and the prices were quite steep. 187 more words

Porter Davis

Unity C# Game Design Pattern: Decorator

 using UnityEngine;
 
 namespace Decorator
 {
     class Main: MonoBehaviour
     {
         void Start()
         {
             IronSword ironSword = new IronSword();
             EnhanceWeapon enhancer = new EnhanceWeapon (ironSword);
             enhancer.Enhance ();
 
             HappySword happySword = new HappySword();
             enhancer = new EnhanceWeapon (happySword);
             enhancer.Enhance ();
         }
     }
         
     //Component interface
     public interface IWeapon
     {
         string SwordName { get; }
         float Damage { get;}
         int Level { get;}
         float Cost { get;}
     }
 
     //ConcreteComponent
     public class IronSword : IWeapon
     {
         public string SwordName{
             get { return "Iron Sword";}
         }
 
         public float Damage
         {
             get { return 5; }
         }
 
         public int Level
         {
             get { return 1; }
         }
 
         public float Cost
         {
             get { return 15; }
         }
     }
 
     //ConcreteComponent
     public class HappySword : IWeapon
     {
         public string SwordName{
             get { return "HappySword Sword";}
         }
 
         public float Damage
         {
             get { return 100; }
         }
 
         public int Level
         {
             get { return 10; }
         }
 
         public float Cost
         {
             get { return 200; }
         }
     }
         
     //Decorator
     public abstract class WeaponStats : IWeapon
     {
         public IWeapon weapon;
 
 
 
         public WeaponStats(IWeapon weapon)
         {
             this.weapon = weapon;
         }
 
         public string SwordName{
             get { return weapon.SwordName;}
         }
 
         public float Damage
         {
             get { return weapon.Damage; }
         }
 
         public int Level
         {
             get { return weapon.Level; }
         }
 
         public float Cost
         {
             get { return weapon.Cost; }
         }
 
     }
 
     //ConcreteDecorator
     public class EnhanceWeapon : WeaponStats
     {
         public EnhanceWeapon(IWeapon weapon) : base(weapon) {
 
         }
 
         public void Enhance(){
             float newDamage = weapon.Damage * 1.25f;
             float newLevel = weapon.Level + 1;
             float newCost = weapon.Cost * 3f;
 
             Debug.Log (weapon.SwordName +": Level "+weapon.Level+" : Damage:"+weapon.Damage+" ,Cost:"+weapon.Cost+"g");
             Debug.Log ("Enhanced " +weapon.SwordName +": New Level "+newLevel+" : New Damage:"+newDamage+" , New Cost:"+newCost+"g");
         }
             
     }
 
 
 
 
 
 }
C#

Decorator Pattern in Java

Decorator pattern provides to add additional responsibilities to an object at runtime. There is no need to create subclasses. Lets look at UML diagram and explain the pattern with an example; 448 more words

Need Painter And Decorator? Know Their Expertise First

Right now there are many different types of painter and decorator that most belong to the expert painter banner. As a result, it may be difficult to recognize specifically which you require. 421 more words

House Painting