ElaKiri Programmer's Club

TNHM

Well-known member
  • Jan 3, 2017
    5,328
    15,493
    113
    හෙනයා;22917261 said:
    මචන් regex validations entity classes වල setters වල ලියන එක අව්ල්ද? නැද්ද?

    depends.
    Normally validations setters walata danne na.
     

    හෙනයා

    Well-known member
  • May 23, 2014
    16,754
    16,865
    113
    Kottawa
    depends.
    Normally validations setters walata danne na.

    11.gif
     

    හෙනයා

    Well-known member
  • May 23, 2014
    16,754
    16,865
    113
    Kottawa
    Angular කරන කට්ටියගෙන් පොඩි උපදෙසක් ඕනේ..

    PHP:
    1.  getStudent(id: string): Student {
    2.    let newStudent: Student;
    3.    this.studentService.findOneById(id).subscribe(student => {
    4.      student.links.forEach(link => {
    5.        if (link.rel === 'laptop') {
    6.          this.laptopService.findOneByUrl(link.href).subscribe(laptop => {
    7.            student.laptop = laptop;
    8.          });
    9.        } else if (link.rel === 'batch') {
    10.          this.batchService.findOneByUrl(link.href).subscribe(batch => {
    11.            student.batch = batch;
    12.          });
    13.        } else if (link.rel === 'subject') {
    14.          this.subjectService.findAllByUrl(link.href).subscribe(subjects => {
    15.            student.subjects = subjects;
    16.          });
    17.        }
    18.      });
    19.      newStudent = student;
    20.    });
    21.    return newStudent;
    22.  }

    මේ වගේ තැනකදී Observable එකකට subscribe වෙලා call back function එක ඇතුලේ ඕනේ දේ ලියන්නේ නැතුව යට line වල ලිව්වම callback එක complete වෙන්න කලින් යට line execute වෙනවනේ..
    example එකක් විදිහට 19 වෙනි line එක execute වෙද්දී subscribe වෙලා ගන්න
    PHP:
    laptop, batch, subjects
    objects student එකට assign වෙලා නෑ.. ඒ වගේම 21 වෙනි line එකේ return වෙන්නේ empty
    PHP:
    newStudent
    object එකක්..
    මේ වගේ තැන්වලදී කරන්න පුළුවන් දේවල් මොනාද? නැත්තම් callback ඇතුලේ callback ලියන්න වෙනවද?​
     

    amilabanuka

    Well-known member
  • Sep 30, 2006
    7,292
    881
    113
    Thama math hoyanooo....
    හෙනයා;22917261 said:
    මචන් regex validations entity classes වල setters වල ලියන එක අව්ල්ද? නැද්ද?

    entity level ekatama validate nokarapu data gena eka echcharama hoda wadak neme. mama nam prefer karanne kalin validate karana eka. api DTO level ekaka nam liwata kamak na kiyanna puluwan.
     

    හෙනයා

    Well-known member
  • May 23, 2014
    16,754
    16,865
    113
    Kottawa
    හෙනයා;22949129 said:
    Angular කරන කට්ටියගෙන් පොඩි උපදෙසක් ඕනේ..

    PHP:
    1.  getStudent(id: string): Student {
    2.    let newStudent: Student;
    3.    this.studentService.findOneById(id).subscribe(student => {
    4.      student.links.forEach(link => {
    5.        if (link.rel === 'laptop') {
    6.          this.laptopService.findOneByUrl(link.href).subscribe(laptop => {
    7.            student.laptop = laptop;
    8.          });
    9.        } else if (link.rel === 'batch') {
    10.          this.batchService.findOneByUrl(link.href).subscribe(batch => {
    11.            student.batch = batch;
    12.          });
    13.        } else if (link.rel === 'subject') {
    14.          this.subjectService.findAllByUrl(link.href).subscribe(subjects => {
    15.            student.subjects = subjects;
    16.          });
    17.        }
    18.      });
    19.      newStudent = student;
    20.    });
    21.    return newStudent;
    22.  }

    මේ වගේ තැනකදී Observable එකකට subscribe වෙලා call back function එක ඇතුලේ ඕනේ දේ ලියන්නේ නැතුව යට line වල ලිව්වම callback එක complete වෙන්න කලින් යට line execute වෙනවනේ..
    example එකක් විදිහට 19 වෙනි line එක execute වෙද්දී subscribe වෙලා ගන්න
    PHP:
    laptop, batch, subjects
    objects student එකට assign වෙලා නෑ.. ඒ වගේම 21 වෙනි line එකේ return වෙන්නේ empty
    PHP:
    newStudent
    object එකක්..
    මේ වගේ තැන්වලදී කරන්න පුළුවන් දේවල් මොනාද? නැත්තම් callback ඇතුලේ callback ලියන්න වෙනවද?​

    Up
     

    TNHM

    Well-known member
  • Jan 3, 2017
    5,328
    15,493
    113
    හෙනයා;22949129 said:
    Angular කරන කට්ටියගෙන් පොඩි උපදෙසක් ඕනේ..

    PHP:
    1.  getStudent(id: string): Student {
    2.    let newStudent: Student;
    3.    this.studentService.findOneById(id).subscribe(student => {
    4.      student.links.forEach(link => {
    5.        if (link.rel === 'laptop') {
    6.          this.laptopService.findOneByUrl(link.href).subscribe(laptop => {
    7.            student.laptop = laptop;
    8.          });
    9.        } else if (link.rel === 'batch') {
    10.          this.batchService.findOneByUrl(link.href).subscribe(batch => {
    11.            student.batch = batch;
    12.          });
    13.        } else if (link.rel === 'subject') {
    14.          this.subjectService.findAllByUrl(link.href).subscribe(subjects => {
    15.            student.subjects = subjects;
    16.          });
    17.        }
    18.      });
    19.      newStudent = student;
    20.    });
    21.    return newStudent;
    22.  }

    මේ වගේ තැනකදී Observable එකකට subscribe වෙලා call back function එක ඇතුලේ ඕනේ දේ ලියන්නේ නැතුව යට line වල ලිව්වම callback එක complete වෙන්න කලින් යට line execute වෙනවනේ..
    example එකක් විදිහට 19 වෙනි line එක execute වෙද්දී subscribe වෙලා ගන්න
    PHP:
    laptop, batch, subjects
    objects student එකට assign වෙලා නෑ.. ඒ වගේම 21 වෙනි line එකේ return වෙන්නේ empty
    PHP:
    newStudent
    object එකක්..
    මේ වගේ තැන්වලදී කරන්න පුළුවන් දේවල් මොනාද? නැත්තම් callback ඇතුලේ callback ලියන්න වෙනවද?​

    PHP:
    this.laptopService.findOneByUrl(link.href).subscribe(laptop => {
              student.laptop = laptop;
    });


    මේ වගේ ලියලා තියෙන ඒවා ඔක්කොම async operations.
    ඔතනදි වෙන්නේ උබ student object එකක් හදලා ඒක return කරනවා. ඊටපස්සේ subscribe arrow function ඒක ඇතුලෙදි assign කරන්නේ data. ඔතනදි උබට return කරන්න බැ object එකක්.

    කරන්න තියෙන්නේ student object එකක් හදලා callbacks වලදී data assign කරලා. ඔක්කොම callback ටික ඉවර උනාම උබේ function එකෙන් callback එකක් කෝල් කරන්න.


    getStudent(studentID : String, callback) {
    let student = new Student();
    this.studentService.findOneById(studentID).subscribe(data => {
    //do what you want here
    callback(student);
    });
    }

    ඕක කෝල් කරන්නේ මෙහෙමයි .
    getStudent("1", (student) => {
    console.log(student);
    });


    නැතිනම් promise use කරන්න async/await එක්ක.

    async getStudent(studentID: String){

    let student = new Student();
    let dbResult = await this.studentService.findOneById(studentID);
    //do what you want here.
    return student;
    }

    මේක කෝල් කරන්නේ මෙහෙමයි

    getStudent("1").then(student => {
    console.log(studnet);
    }).catch(err => {
    console.log('error happened', err);
    });
     

    හෙනයා

    Well-known member
  • May 23, 2014
    16,754
    16,865
    113
    Kottawa

    Ubada oka damme? Dila tiyenna answer eka therunada?

    PHP:
    this.laptopService.findOneByUrl(link.href).subscribe(laptop => {
              student.laptop = laptop;
    });


    මේ වගේ ලියලා තියෙන ඒවා ඔක්කොම async operations.
    ඔතනදි වෙන්නේ උබ student object එකක් හදලා ඒක return කරනවා. ඊටපස්සේ subscribe arrow function ඒක ඇතුලෙදි assign කරන්නේ data. ඔතනදි උබට return කරන්න බැ object එකක්.

    ....

    Reta reply ekak daanam machan.. Podi dewal tikak tiyenawa ahaganna...
     

    TNHM

    Well-known member
  • Jan 3, 2017
    5,328
    15,493
    113
    හෙනයා;23154415 said:
    Ubada oka damme? Dila tiyenna answer eka therunada?



    Reta reply ekak daanam machan.. Podi dewal tikak tiyenawa ahaganna...

    Ela. Machan
     

    sw7x

    Well-known member
  • Nov 12, 2007
    11,114
    2,296
    113
    හෙනයා;23154415 said:
    Ubada oka damme? Dila tiyenna answer eka therunada?


    කමෙන්ට් එකක් දෑම්ම බන් answer එක යටින්
    මට තෙරෙන්නෙ නෑත්තෙ

    ක්ලාස්ස් වල මෙතොඩ් වලට දාන්නෙ එ ක්ලාස් එකෙ actions එහෙම නත්නම් behaviours,එ කියන්නෙ එ ක්ලාස් එකට කරන්න පුලුවන් දෙවල් නෙද.... ???

    අනික oop වල defination එකෙ තියෙන්නෙත් එහෙමනෙ

    but මෙයා කියන්නෙ Usually methods should be on the object that is being acted upon (the "subject" of the action).
     
    Last edited:

    TNHM

    Well-known member
  • Jan 3, 2017
    5,328
    15,493
    113
    කමෙන්ට් එකක් දෑම්ම බන් answer එක යටින්
    මට තෙරෙන්නෙ නෑත්තෙ

    ක්ලාස්ස් වල මෙතොඩ් වලට දාන්නෙ එ ක්ලාස් එකෙ actions එහෙම නත්නම් behaviours,එ කියන්නෙ එ ක්ලාස් එකට කරන්න පුලුවන් දෙවල් නෙද.... ???

    අනික oop වල defination එකෙ තියෙන්නෙත් එහෙමනෙ

    but මෙයා කියන්නෙ Usually methods should be on the object that is being acted upon (the "subject" of the action).

    Uba therum aran thiyenawa waradi. Mama comment ekak dannam edara gihin
     

    හෙනයා

    Well-known member
  • May 23, 2014
    16,754
    16,865
    113
    Kottawa
    කමෙන්ට් එකක් දෑම්ම බන් answer එක යටින්
    මට තෙරෙන්නෙ නෑත්තෙ

    ක්ලාස්ස් වල මෙතොඩ් වලට දාන්නෙ එ ක්ලාස් එකෙ actions එහෙම නත්නම් behaviours,එ කියන්නෙ එ ක්ලාස් එකට කරන්න පුලුවන් දෙවල් නෙද.... ???

    අනික oop වල defination එකෙ තියෙන්නෙත් එහෙමනෙ

    but මෙයා කියන්නෙ Usually methods should be on the object that is being acted upon (the "subject" of the action).



    මන් පොඩ්ඩක් පැහැදිලි කරන්නම් මන් දන්න විදිහට.. අඩු පාඩු තියේ නම් කියන්න..

    ඉස්සෙල්ල class diagram එකක එන classes වර්ග ටික අදුරගෙන ඉන්න ඕනේ..

    සාමාන්‍යෙන් use කරන stereotypes වර්ග 3 ක් තියෙනවා..
    Boundary
    Control
    Entity

    මේක කෙලින්ම match වෙනවා MVC වලට..

    දැන් එතකොට උබට මීටර් වෙලා තියෙන්නේ Manager project handle කරනවා කියල නේ.. එහෙම්මමත් නෙමෙයි.. මොකද..

    සාමන්යෙන් අපි domain එකක් analyse කරද්දී අපිට අහුවෙනවා things.. සරලවම කිව්වොත් nouns.. මෙතැනදී නම් Project, Manager, Employee වගේ එව්වා.. ඒවා අපි කියන්නේ Entity classes කියල.. ඒ කිව්වේ මොනාහරි information එකක් represent කරන්න යොදාගන්න classes..

    සාමාන්‍යෙන් මේ classes වල objects තමුන් විසින්ම වැඩ කරන්නේ නෑ.. වෙන කෙනෙක් තමා මෙයාව යොදාගෙන වැඩ ගන්නේ..



    අන්න ඒ ජාතියේ classes වලට තමා කියන්නේ controller classes කියල.. එතකොට මෙතන Project class එකට අනුව නම් එක හසුරවන්නේ ProjectController class එක.. ඒ කිව්වේ මෙන්න මේ methods ටික..

    createProject()
    deleteProjectById()
    updateProjectById()
    isProjectDeadlinExceed()

    එතකොට මේ methods execute කරද්දී යොදාගන්න class එක තමා entity class එක.. example එකක් විදිහට createProject() කියන එකට අපි යවන්න ඕනේ අපිට save කරන්න ඕනේ project එකේ instance එකක්.. ඒ කිව්වේ Project entity class එකේ instance එකක් හදල එකට අපිට ඕනේ data ටික set කරලා එක බාර දෙන්න ඕනේ createProject() method එකට..

    ඊළගට මේ methods දෙක ගත්තොත් මේවා අයිති වෙන්නේ ManagerController class එකට.. මොකද මේ methods වලින් handle කරන්නේ managers ලගේ details නිසා..

    updateManagerInfo()
    addQualificationToManager()

    මේවා ProjectController එකට දාන්න බෑ මොකදා cohesion principal එක violate වෙන නිසා..
    class එකක තියෙන්න ඕනේ ඒ class එකෙන් කරන්න ඕනේ දේවල් විතරයි..

    මන් හිතන්නේ stackoverflow එකේ answer එකේ අරු දාල තියෙන portfolio class එකෙනුත් අදහස් වෙන්නේ මේ වගේ idea එකක් වෙන්න ඇති..

    වෙන අයගෙනුත් ideas අරගෙන හොදයි කියල හිතෙන එකක් බලන්න.. මම දැම්මේ මම හිතන විදිහ..

    මේ tutorial එක බැලුව නම් හොද ideas ටිකක් ගන්න පුළුවන්..

    https://www.lynda.com/Java-tutorials/Foundations-Programming-Object-Oriented-Design/96949-2.html

    P. S.

    isProjectDeadlinExceed() method එක Project class එකේ ලිව්වත් වරදක් නෑ එතකොට අපිට කෙලින්ම call කරල true, false ගන්න පුළුවන්..
    sampleProject.isProjectDeadlinExceed();

    නැත්තම් controller class එකේ ලියල ඒ method එකට Project object එක pass කරන්න ඕනේ..

    PHP:
    isProjectDeadlinExceed(Project project){
       //logic
    }
     
    Last edited:
    • Like
    Reactions: ilanganthilaka

    හෙනයා

    Well-known member
  • May 23, 2014
    16,754
    16,865
    113
    Kottawa
    Ela. Machan


    මචන් එතැනදී 1 වෙනි පාර subscribe උනාම එන්නේ මේ වගේ result එකක්..



    මේ object එකේ primitive fields (id, name, age...) වගේ එව්වා කොහොමත් ගන්න පුළුවන්.. හැබැයි related objects ගන්න තමයි link array එකේ තියෙන href එකේ තියෙන url එක subscribe කරන්නේ..

    උබ කියපු 1 වෙනි method එකට අනුව කලොත් නම් මෙහෙම අවස්ථාවකදී ඒ callback එක කලින් call වෙනවා..

    PHP:
    getStudent(studentID : String, callback) {
       let newStudent = new Student();
       this.studentService.findOneById(studentID).subscribe(student => {
       newStudent = student;
       student.links.forEach(link =>{
          laptopService.findOneById(link.href).subscribe(laptop => {
             newStudent.laptop = laptop;
          });
       });
       callback(student);
    });
    }
    
    getStudent("1", (student)=> log(student));

    දෙවෙනි ක්‍රමේ ගැන ගැන නම් දන්නේ නෑ බන්.. :(:(

    මට මේකට විසදුමක් අහු උනා.. බුකියේ group එකකින් ඇහුවම කිව්වා forkJoin() use කරන්න කියල... මේ විදිහට...



    හැබැයි මේකේ තියෙන අවුල මොකක්හරි Observable එකක් null උනොත් මුළු forkJoin එකම වැඩ කරන්නේ නෑ.. :sorry::sorry::sorry: