在面对一个用户需求时,通常需要应用到代码组织模式、数据存储、用户交互与展现等具体设计内容,其中最重要的部分,可能是命名,此时,AI就能够发挥其强大的优势:
第一: 用中文说出准确的需求描述
class Pizza {
var size: String?
var cheese: Bool = false
var pepperoni: Bool = false
var mushrooms: Bool = false
}
第二:AI帮助生成类、变量、方法名称,简直不要太爽
class PizzaBuilder {
private var pizza: Pizza
init() {
self.pizza = Pizza()
}
func withSize(_ size: String) -> PizzaBuilder {
self.pizza.size = size
return self
}
func withCheese(_ cheese: Bool) -> PizzaBuilder {
self.pizza.cheese = cheese
return self
}
func withPepperoni(_ pepperoni: Bool) -> PizzaBuilder {
self.pizza.pepperoni = pepperoni
return self
}
func withMushrooms(_ mushrooms: Bool) -> PizzaBuilder {
self.pizza.mushrooms = mushrooms
return self
}
func build() -> Pizza {
return self.pizza
}
}
第三: 根据需要,优化和调整部分名称,使其符合你的心意
let pizza = PizzaBuilder()
.withSize("Large")
.withCheese(true)
.withPepperoni(true)
.withMushrooms(false)
.build()
总之,借助于AI辅助,使命名效率大幅提高,并很快就能够得到,简洁、准确、易读的命名, 赶紧用起来吧。