If I understand your question you are not aware of the MVC design pattern. If I put it in simple terms
Model -> Database Access
Controller -> Coordination
View -> Data Representation
You will have to read more on the above topic. Also read about how to create a custom component in Joomla.