OOP

what is better in these two code in terms of oop

http://codeviewer.org/view/code:43d7
or
http://codeviewer.org/view/code:43d8
I think the second one is best. If you want to have a rectangle class that is. But you should use a more descriptive name for the function. set_values could be called set_size, set_dimensions or something like that.

In the first one the Rectangle class is pointless. All data that is needed to calculate the result is passed to the function so it would be better to just make it a normal function.
1
2
3
4
5
int rect_area(int width, int height) {
	return width * height;
}

cout << "rect area: " << rect_area(1, 2) << endl;

Last edited on
so youre saying in the first one that it is like a normal function and the class is all useless and also its like not having a private data members ty ty ty
Last edited on
Topic archived. No new replies allowed.