how to create a method which creates new instance from class