set model properties at function definition

My method needs to be strictly typed. If possible, I wanted to save some line of codes, setting the model properties from the parameter input by putting the model properties setter directly at the function definition.

The current working code:

class Connector {
  static def entityQuery(
    String httpMethod, 
    String typeName, 
    String orderFieldName,
    String orderOrderType,
    String orderOrderName
  ){
    EntityQuery model = new EntityQuery()
    model.httpMethod = httpMethod
    model.typeName = typeName
    model.order.fieldName = orderFieldname
    model.order.OrderType = orderOrderType
    model.order.OrderName = orderOrderName

    convertToMap( model )
  }
}

wanted to achieve something like..

class Connector {

  static def entityQuery(
    String model.httpMethod, 
    String model.typeName, 
    String model.orderFieldName,
    String model.orderOrderType,
    String model.orderOrderName
  ){
    convertToMap( model )
  }
}

There are many methods like entityQuery()


Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.