ModeImpl cannot be resolved to a type

Pankaj Kumar, modified 5 Years ago. Regular Member Posts: 101 Join Date: 7/27/14 Recent Posts
Hi All,
In 6.2 we are able to instance ModleImpl.e.g
Model model=new ModelImpl();but in Liferay 7.2  we cannot do it.Can  any body tell me how we can do this in Liferay 7.2 version.
Thanks,Pankaj Semwal
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Pankaj Kumar:

In 6.2 we are able to instance ModleImpl.e.g
Model model=new ModelImpl();but in Liferay 7.2  we cannot do it.Can  any body tell me how we can do this in Liferay 7.2 version.
It's wrong to instantiate a ModelImpl directly in client code: Encapsulate it in a service and hand it out.
You want client code to purely be dependent on the interface, so that you can hand out any kind of wrapper at any time. Your client code is only dependent on the api, never on the service implementation.
It was always wrong (bad style) to access implementation classes. Luckily now it's also impossible without going through hoops. Don't go through hoops - have your service provide whatever it wants, under the Model interface.
Pankaj Kumar, modified 5 Years ago. Regular Member Posts: 101 Join Date: 7/27/14 Recent Posts
Thanks Olaf for your quick response.I did like this.InModeLocalServiceIml classgetInstance(){Model model=new ModelImpl()
return model;}
thumbnail
David H Nebinger, modified 5 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
Again, this was wrong.

Instead, in ModelLocalServiceImpl, you should have just called "createModel(0);" and let Liferay construct one properly.

Oh, and the way you did it in 6.2 was also wrong, it should have been createModel(0) there too.