programming help>>>

Kasun k

Well-known member
  • Mar 11, 2009
    10,357
    492
    83
    United States
    INTERFACE ekak kiyanne mokadda.

    class ekak hadala extend karana ekei INTERFACE ekak hadala implement karana ekei wenasa mokadda

    Class akak ubata aka parai, naththan aka class akai extrend karanna puluwan. Interfaces ona tharam implement karanna puluwan. Interfaces use karanne godak ma multiple inheritance walata. Interface akaki , Abstract class akai wedi wenasak naha.
     

    Jolly_Roger

    Well-known member
  • May 2, 2009
    10,600
    1,606
    113
    Colombo XOR Matara
    machan C# wala wage multiple inheritance support karanne nathi welawata multiple classes walin methods call karanna thamai use karanne. runtime polymorphism kiyalath kiyanawa.

    me wage

    public class FileLog : ILog {

    public void Log(string text)
    {
    // write text to a file
    }
    }

    public class DatabaseLog : ILog
    {
    public void Log(string text)
    {
    // write text to the database
    }
    }

    public interface ILog
    {
    void Log(string text);
    }

    public class SomeOtherClass
    {
    private ILog _logger;
    public SomeOtherClass(ILog logger)
    {
    // i don't know if logger is the FileLog or DatabaseLog
    // but i don't need to know that as long as its implementing ILog this._logger = logger; logger.Log("Hello World!);
    }
    }

    interface ekak kiyanne contract ekak. mokakhari class ekak interface ekak inherit karnawa nam eke thiyana hama proprty ekakma class eke implement karanna ona.

    interfaces use kalama loose coupling achieve karanna puluwan. :):)
     
    • Like
    Reactions: DooA

    wijcha

    Junior member
  • Nov 3, 2008
    172
    13
    18
    INTERFACE ekak kiyanne mokadda.

    class ekak hadala extend karana ekei INTERFACE ekak hadala implement karana ekei wenasa mokadda

    Machan, interface eke implemetation mukuthma nane. E unata class eke implementation thiyenawane. nikamata api hithamu test kiyala method ekak thiyanawa eke implementation eka (method body) kohe thibunath ekai. ehema welawata interface use karana eka therumak na. mokada api hema class ekema ekama method eka implement karanna wena nisa. anith hema welawema interface use karana eka hondai.
     
    • Like
    Reactions: DooA

    rhn123

    Well-known member
  • Jul 20, 2012
    759
    37
    48
    class eka athule methods constructors properties okkoma thiyenawane
    ex:
    public class world
    {
    public void showMsg()
    {
    System.out.writeline("blashhs jaskja");
    }
    }

    class eke methods define karala thiyenne.
    interface eke thiyenne method declaration eka witharai.definition eka karanne na.

    Inteface Iworld
    {
    public void showMsg();
    }

    java wala implement karanwanam e interface ekakin extend karanwanam class ekakin.
    interface ekak implement karanwa kiyanne aniwaryenma ara showMsg eka oya implement karana class eka athule define karanna one. extends karanwanam ara methd ekata access ganna puluwan oya extend karana class eke idan.

    anith aya man waradinam kiyanna
     
    Last edited:
    • Like
    Reactions: DooA

    DJvodka

    Well-known member
  • Mar 31, 2009
    3,375
    292
    83
    A land like no other
    Interface ඒකක් කියන්ෙන කියන්නෙ ලක්ශනයක් හෝ කන්සෙප්ට් එකක්. ඒක නිකන් template එකක් වගේ. කිසිම විදියකින් multiple inhereitance වලට නෙමෙයි ඒක තියෙන්නෙ. Interface එකක් යූස් කරන්නෙ implementation එකක් නැති වුනාම. class inheritance වලින් කියවෙන්නෙ is-a relationship එකක්. Eg:

    Vehicle--->Car = is-a relationship : class inheritance is used
    Flyable chacteristic
    Car implements Flyable = Now car can fly : interface is used
    Vehicle--->Lorry = is-a relationship : class inheritance is used
    Lorry can fly? No.If you want, implement the flyable interface.
    Car ===> New Car can be created
    Flyable Car ===> New Flyable Car can be created
    Flyable ===> New flyable object cannot be created. Why? Flyable is a charcteristic or concept.

    දැන් මේක කරන වැරදි විදිය තමයි Flyable කියල class එකක් හදලා Car එක extend කරන එක.
    මොකද Car එක Flyable දෙයක් නොවන නිසා.
     

    DooA

    Well-known member
  • Jun 22, 2011
    5,202
    773
    113
    ආගිය අතක් නැත
    Interface ඒකක් කියන්ෙන කියන්නෙ ලක්ශනයක් හෝ කන්සෙප්ට් එකක්. ඒක නිකන් template එකක් වගේ. කිසිම විදියකින් multiple inhereitance වලට නෙමෙයි ඒක තියෙන්නෙ. Interface එකක් යූස් කරන්නෙ implementation එකක් නැති වුනාම. class inheritance වලින් කියවෙන්නෙ is-a relationship එකක්. Eg:

    Vehicle--->Car = is-a relationship : class inheritance is used
    Flyable chacteristic
    Car implements Flyable = Now car can fly : interface is used
    Vehicle--->Lorry = is-a relationship : class inheritance is used
    Lorry can fly? No.If you want, implement the flyable interface.
    Car ===> New Car can be created
    Flyable Car ===> New Flyable Car can be created
    Flyable ===> New flyable object cannot be created. Why? Flyable is a charcteristic or concept.

    දැන් මේක කරන වැරදි විදිය තමයි Flyable කියල class එකක් හදලා Car එක extend කරන එක.
    මොකද Car එක Flyable දෙයක් නොවන නිසා.

    ado thnax machn.. help karapu okkotama thnx. kattiyata salakala athi