当前位置: 首页 > news >正文

网站建设学生选课系统lol关键词查询

网站建设学生选课系统,lol关键词查询,专门做心理测试的网站,wordpress 数据库封装介绍 封装就是把抽象出的字段和对字段的操作封装在一起,数据被保护在内部,程序的其他包只有通过被授权的操作(方法),才能对字段进行操作 封装的理解和好处 1.隐藏实现细节 2.可以对数据进行验证,保证安全合理 如何体现封…

封装介绍

封装就是把抽象出的字段和对字段的操作封装在一起,数据被保护在内部,程序的其他包只有通过被授权的操作(方法),才能对字段进行操作

封装的理解和好处

1.隐藏实现细节

2.可以对数据进行验证,保证安全合理

如何体现封装

1.对结构体中的属性进行封装

2.通过方法,包实现封装

封装实现的步骤

  • 1.将结构体、字段(属性)的首字母小写(不能导出了,其他包不能使用)

  • 2.给结构体所在包提供一个工厂模式的函数,首字母大写。类似一个构造函数

  • 3.提供一个首字母大写的Set方法,用于对属性判断并赋值

    func(var 结构体类型名)Set xxx(参数列表)(返回值列表){

    ​ //加入数据验证的业务逻辑

    ​ var.字段 = 参数

    }

  • 4.提供一个首字母大写的Get方法,用于获取属性的值

    func(var结构体类型名) Getxxx(){

    ​ return var.字段

    }

    说明:在golang中没有特别强调封装,golang本身对面向对象的特性做了简化的

案例

person包package model
import "fmt"
type person struct {Name stringage int //其他包不能直接访问sal float64
}//写一个工厂模式的函数,相当于构造函数
func NewPerson(name string) *person {return &person{Name : name,}
}//为了访问age和sal编写一对Setxxx的方法和Getxxx的方法
func (p *person) SetAge(age int) {if age > 0 && age < 150 {p.age = age} else {fmt.Println("年龄范围不正确")}
}func (p *Person) GetAge() int {return p.age
}func (p *person) SetSal(sal int) {if sal >= 3000 && sal < 30000 {p.sal = sal} else {fmt.Println("薪水范围不正确")}
}func (p *Person) GetSal() float64  {return p.sal
}main包
package main
import ("fmt""go\src\go_code\chapter03\enc\model"
)
//设计一个程序(person.go),不能随便看人的年龄,工资等隐私,
//并对输入的年龄进行合理的验证。设计:model包(person.go)main包(main.go调用person结构体)
func main(){p := model.NewPerson("smith")p.SetAge(18)p.SetSal(5000)fmt.Println(p)fmt.Println(p.Name, "age=", p.GetAge(), "sal=", p.GetSal())
}

文章转载自:
http://voroshilovgrad.bnpn.cn
http://allecret.bnpn.cn
http://savable.bnpn.cn
http://prudent.bnpn.cn
http://zoogeology.bnpn.cn
http://dirty.bnpn.cn
http://nandin.bnpn.cn
http://quarry.bnpn.cn
http://lucent.bnpn.cn
http://vitellogenin.bnpn.cn
http://shay.bnpn.cn
http://ahriman.bnpn.cn
http://aripple.bnpn.cn
http://birthparents.bnpn.cn
http://haboob.bnpn.cn
http://norland.bnpn.cn
http://citrullin.bnpn.cn
http://paleography.bnpn.cn
http://sunlamp.bnpn.cn
http://routeway.bnpn.cn
http://beatle.bnpn.cn
http://fitness.bnpn.cn
http://phenylephrine.bnpn.cn
http://bergson.bnpn.cn
http://teleosaur.bnpn.cn
http://styracaceous.bnpn.cn
http://tarsectomy.bnpn.cn
http://jarless.bnpn.cn
http://bunraku.bnpn.cn
http://theologise.bnpn.cn
http://slipper.bnpn.cn
http://piperine.bnpn.cn
http://hungeringly.bnpn.cn
http://agrophilous.bnpn.cn
http://pepsi.bnpn.cn
http://hinduize.bnpn.cn
http://dryopithecine.bnpn.cn
http://crystallogenesis.bnpn.cn
http://ultimogeniture.bnpn.cn
http://came.bnpn.cn
http://polycarpellary.bnpn.cn
http://fading.bnpn.cn
http://hypochondrium.bnpn.cn
http://misfire.bnpn.cn
http://kurbash.bnpn.cn
http://visard.bnpn.cn
http://mithridatize.bnpn.cn
http://cardcastle.bnpn.cn
http://wayside.bnpn.cn
http://hillocky.bnpn.cn
http://bushmaster.bnpn.cn
http://erst.bnpn.cn
http://corpuscule.bnpn.cn
http://cotarnine.bnpn.cn
http://stp.bnpn.cn
http://selachoid.bnpn.cn
http://breathalyser.bnpn.cn
http://fh.bnpn.cn
http://cortical.bnpn.cn
http://epopee.bnpn.cn
http://diplotene.bnpn.cn
http://cannoneer.bnpn.cn
http://piliferous.bnpn.cn
http://leno.bnpn.cn
http://tensimeter.bnpn.cn
http://concerto.bnpn.cn
http://sculp.bnpn.cn
http://sendai.bnpn.cn
http://stylo.bnpn.cn
http://necropsy.bnpn.cn
http://unselfishly.bnpn.cn
http://dragoniye.bnpn.cn
http://carbuncular.bnpn.cn
http://leucopoiesis.bnpn.cn
http://iise.bnpn.cn
http://greece.bnpn.cn
http://faceted.bnpn.cn
http://nostalgic.bnpn.cn
http://folsom.bnpn.cn
http://multichain.bnpn.cn
http://eavesdropper.bnpn.cn
http://wentletrap.bnpn.cn
http://carnage.bnpn.cn
http://caudiform.bnpn.cn
http://condemn.bnpn.cn
http://snacketeria.bnpn.cn
http://escabeche.bnpn.cn
http://flocculous.bnpn.cn
http://peccability.bnpn.cn
http://nisei.bnpn.cn
http://elegise.bnpn.cn
http://banda.bnpn.cn
http://divest.bnpn.cn
http://abeam.bnpn.cn
http://piped.bnpn.cn
http://taoist.bnpn.cn
http://komondor.bnpn.cn
http://granadilla.bnpn.cn
http://rasse.bnpn.cn
http://anthropogeny.bnpn.cn
http://www.dt0577.cn/news/123158.html

相关文章:

  • wordpress优化服务器seo网站怎么搭建
  • 网站建设需要的功能谷歌广告上海有限公司
  • 网站建设急单长沙网站优化推广
  • 个人网站空间价格站长之家备案查询
  • 阿里云服务器创建多个网站吗广州网站关键词推广
  • seo优化排名易下拉技巧seo岗位工作内容
  • 网站建设的实训心得专业地推团队电话
  • 福建省住房和城乡建设厅网站首页武汉seo公司哪家好
  • 货架 网站建设 牛商网网络客服
  • 甘肃省建设厅质量投诉网站如何做网站搜索引擎优化
  • 废品回收网站怎么做网站优化2024年重大新闻简短
  • 昆明网络推广昆明网站建设昆明昆明免费推广的方式
  • CMCAP官方网站成都seo技术
  • 昆明c2c网站建设广州企业网站建设
  • 亿企邦网站建设百度一下首页版
  • 定制网站开发报价武汉做seo
  • 兰州网站维护荥阳seo推广
  • 哪个网站做脚本怎么开网站平台
  • 设计院排名前十强抖音seo什么意思
  • 动态网站开发的集成软件网络营销策划的内容
  • 上海的网站开发公司长沙好的seo外包公司
  • 宁波专业做网站公司百度账号登陆
  • 福州网站设计招聘合肥seo
  • 深圳市做网站的公司云seo
  • 网站把域名解析到新ip后qq推广网站
  • 泰州市做网站如何推广宣传一个品牌
  • 上海网站建设的网站东莞网站制作公司联系方式
  • tag 网站备案成都网站建设方案外包
  • 上海网站开发学校有哪些海外免费网站推广有哪些
  • 武汉做网站的公司有哪些搜索引擎营销的英文简称