Search Blog

Search duranek.blogspot.com

Wednesday, February 8, 2012

Software Design Principles

Design Principles

1)    Open Close Principle
    Means : open for extension, closed for modification.
    Bir class'i degistirmek istiyorsan, extend et, degistirme.
    Bunun nedeni, backward compatibility, regression testing.

2)     Dependency Inversion Principle

    Dependency injection, for low coupling, inject the dependency,
instead of creating in your body.

3)    Interface Segregation Principle

    Interface'in icine sadece gerekli metodlari koy. Fazla koyarsan
gereksiz yere implementor lar, uygulamak zorunda kalir bu metodlari.

4)    Single Responsibility Principle.
    Eger bir class'in birden cok responsibility'si varsa, o class'i ayirmak lazim.
    Ayirmazsak, o class'i bir nedenden dolayi degistirdigimizde, diger
    nedenlerden dolayi da degistirmek zorunda kalabiliriz.

5)    Liskov's Subtitution Principle

    Child class 'in ozellikleri, base class in ozelliklerini bozmayacak.

    Yani child class'i istedigimiz zaman base class ile degistirebilmeliyiz.
    ve bir sorun yasamamaliyiz

Strongly Typed Language

Tipleri ozellikle belirterek variable yaratilan programlama dili

Proxy Pattern ( Structural )

Proxy Pattern ( Structural )

1) Proxy class is used to control access to another class

3) Complex bir objeyi temsil eden basit bir obje olabilir proxy.
Mesela o objenin creation'i expensive ise, onu basit bir obje temsil edebilir.
ve eger cok gerekliyse gercekten yaratilabilir. ( Virtual Proxy ) 

4) surrogate pattern olarak da bilinir

5) 
-> The proxy object has the same interface as the target object

-> The proxy holds a reference to the target object and can forward requests to
the target as required (delegation!)

-> In effect, the proxy object has the authority the act on behalf of the client to
interact with the target object

6) Adapter different interface verir, proxy same interface verir. Decorator
enhanced interface verir.

7) Access controlleri yapan proxy. ( Proctection Proxy )

8) 

public interface Graphic {

        // a method used to draw the image
      public void draw();
}

public class Image implements Graphic {

    private byte[] data;

    public Image(String filename) {
        // Load the image
        data = loadImage(filename);
    }
        
    public void draw() {
        // Draw the image
        drawToScreen(data);
    }
}

// late initialization, caching
public class ImageProxy implements Graphic {

    // Variables to hold the concrete image
    private String filename;
    private Image content;

    public ImageProxy(String filename) {
        this.filename = filename;
        content = null;
    }

    // on a draw-request, load the concrete image
    //   if we haven't done it until yet.
    public void draw() {
        if (content == null) {
            content = new Image(filename);
        }
        // Forward to the Concrete image.
        content.draw();
    }
}

9) virtual proxy, firewall proxy, remote proxy, protection proxy etc..

Tuesday, February 7, 2012

Adapter Pattern ( Structural )

Adapter Pattern ( Structural Design Pattern)

1)    Adaptee Class : esas obje
    Target Interface : Adapter'in implemente edecegi Interface
    Adapter Class extends Adaptee implements TargetInterface

2)  Elimizdeki objeyi baska bir obje gibi
    kullanmak istiyorsak yazdigimiz arac,
    adaptor.
    
    Y yi de X gibi kullanmak icin.
    Amacin X gibi kullanmak, bu durumda
    target interface X
    
    X kapali kutu gibi dusun. Sadece metodlarini
    biliyorsun.Ya da degistirmek istemiyorsun X'i, ya da hakkin yok.
    
    Adapter implements X {
        member Y;  //adaptee
        Adapter(Y);
    }
    
    main () {
        X a = new Adapter(y);
        // boylece Y de x gibi oldu.
    }
    
3)    Legacy code ya da access olmayan
bir objeyi degistirmemek icin kullanilabilir.

4)    Two way adapter, iki interface
implemente etmek gerekiyor.

Sunday, February 5, 2012

SpringMVC Customize DispatcherServlet XML Name

Normalde DispatcherServlet'in mapping 
ismi xxx ise, xxx-servlet.xml isimli dosyayi
arar. Eger bunu degistirmek istiyorsak web.xml'e
asagidaki kodu eklemek lazim

 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/SpringMVCBeans.xml</param-value>
  </context-param>
 
  <listener>
        <listener-class>
        org.springframework.web.context.ContextLoaderListener
        </listener-class>
  </listener>

Spring Prefix For Element Not Bound Hatasi


Eger spring.xml in asagidaki hatayi veriyorsa

<context:component-scan
  base-package="com.deploymentplan.server.user.GwtRpcController" />

the prefix "context" for element "context:component-scan" is not bound.

Bu,         http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.1.xsd

 xsi:schemaLocation 'a eklenmis fakat xmlns:context="http://www.springframework.org/schema/context" eklenmemis demektir.

Spring MVC DispatcherServlet XML Replacement With Annotation


Spring MVC Controller 2.5.6

1)    @Controller and @RequestMapping to replace the XML configuration.
2)    Controller artik AbstractController'i extend etmiyor ya da Controller interface'ini implemente etmiyor.
    Bunun yerine @Controller yapmamiz yeterli
3)    XML icindeki HandlerMapping yapma geregi kalmadi
4)  <context:component-scan base-package="com.mkyong.common.controller" />
    bu pakette Controller arar.