Google Groups Home
Help | Sign in
Message from discussion Discussion on what-is-grails
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
khomkrit  
View profile
 More options May 16, 2:38 am
From: khomkrit <khomkrit....@gmail.com>
Date: Thu, 15 May 2008 23:38:43 -0700 (PDT)
Local: Fri, May 16 2008 2:38 am
Subject: Re: Discussion on what-is-grails
ตอนนี้ผมกลับมาใน field ของ programming อีกรอบนึงแล้วครับ ต่อไปจะลุย
Groovy เต็มที่ล่ะ :D

สำหรับคำอธิบายของพี่ใหม่ผมอยากจะให้เขียนเป็น page เก็บไว้เลยครับ
เวลาผมอยากจะอ้างถึงเพื่อโปรโมท group จะได้อ้างมาได้ตรงๆ :) แล้วก็
ตรงส่วนของ code น่ะครับ ไม่รู้ว่า Google Group
ในหน้าที่เป็นหน้าเวปนั้น สนับสนุน HTML หรือเปล่า เพราะผมอยากจะให้ทำ
syntax highlight น่ะครับ มันดูสวย น่าอ่าน และดูอ่านง่ายดีครับ

On May 16, 12:03 pm, "Chanwit Kaewkasi" <chan...@gmail.com> wrote:

> งั้นผมจะลองเริ่มอธิบาย Groovy ไว้ใน group บ้างละกันครับ

> เริ่มจากตัวอย่างที่เลียนแบบมาจากหน้าโฮมเพจของ Groovy
> (1-7 คือเลขบรรทัดเพื่อใช้อ้างอิง เวลาเอาไปทดลอง run ให้ลบออกก่อนนะครับ)

> 1. class Greet {
> 2.  def name
> 3.  Greet(who) {
> 4.     name = who[0].toUpperCase() + who[1..-1]
> 5.  }
> 6.  def hello() { println "Hello $name!" }
> 7. }

> def g = new Greet('world')  // สร้างวัตถุ
> g.hello()              // แสดงผล "Hello World!"

> จากตัวอย่างนี้ลอง save ไว้ชื่อ Greet.groovy แล้วสั่ง groovy
> Greet.groovy บน command line ดูก็จะเห็นผลของการทำงาน
> (ผม assume ว่าติดตั้ง Groovy กันเป็นแล้วนะครับ)

> โค้ดด้านบน อธิบายโดยใช้แนวคิดของ Java ได้ดังนี้ครับ
> 1. class Greet มี modifier เป็น public
> 2. def name เป็นการประกาศ bean property นั่นคือด้วยบรรทัดนี้เราจะได้
>    - private field ชื่อ name
>    - getter เมธอด getName
>    - setter เมธอด setName
> โดยอัตโนมัติครับ ถ้าไม่ระบุ type อย่างที่เห็น จะได้ default type เป็น
> Object (java.lang.Object) ครับ
> 3. public constructor รับ argument 1 ตัว
> 4. ตั้งค่า property name โดย who[0] จะเป็นการนำ element ตัวแรกของ who
> ซึ่งรับค่ามาเป็น String แล้วเรียกใช้เมธอด .toUpperCase()
> เพื่อแปลงเป็นตัวอักษรใหญ่ ตามด้วย who[1..-1] ซึ่งหมายถึงเอา String
> ตัวที่เหลือทั้งหมด
> 6. เป็นการประกาศเมธอด hello ซึ่งจริง ๆ แล้วถ้าใช้ def และไม่ระบุ
> return type ของเมธอดไว้เป็น void แบบนี้คือจะใช้ default type เป็น
> Object เหมือนเคยครับ
> 6.1 การใช้ println คือการเรียกใช้ System.out.println ตัว String
> ที่เป็น double qoute จะเป็นข้อความชนิดพิเศษเรียกว่า GString
> ซึ่งจะอ้างอิงถึงตัวแปรด้ว ${ ... } ได้ ( note: 'abc' ใน Groovy คือ
> "abc" ใน Java)
> ตามตัวอย่างนี้คือเอาค่าจาก property name มาแสดงผลด้วยกันกับคำว่า Hello ครับ

> -ชาญวิทย์

> 2008/5/16 somkiat puisungnoen <somkia...@gmail.com>:

> > ตอนนี้ผมกำลังศึกษาตัว Groovy อยู่เลยครับ  มาศึกษาด้วยกันครับ

> > ต่อไปก็จะลงไปที่ Grails ครับ [ ลองใช้เบื้องต้นแล้วชอบครับ ง่ายดี
> > แต่ต้องศึกษาเพิ่มเติมอีกเยอะ ]

> > On May 14, 2:40 am, "noppa...@terasoft.co.th" <toy.New...@gmail.com>
> > wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google