Ideal OOP Design

After learning OOP design then I got to know my programming way was not correct. One should convert physical entities or logically separable components into classes which are reusable and have their own behavior and properties. One must not simply convert all the entities into objects because that would be really cumbersome.

If I am developing a filter system in console that checks if my program wants an integer from user then it must be an integer, it should not be a corrupted value by user’s typing error or wrong input. For such purpose I should create a separate class to manage all its working and behaviors, distinguished from the console working so that if later I want to use that system into GUI then I can.

But creating objects for such class does not makes sense, so I ended up creating everything static from data members to functions which rather seemed like creating somewhat a procedural design with classes. With only one benefit that all the data was bound into units by classes known as encapsulation.

My Question is , Is it fine to have such interfaces with classes or one needs to move back to procedural for them? I often face such problems with designing when applying OOP design to the working mechanisms of my code.

Edit-1

Let me explain the question more precisely suppose you want create a filter system. So you take input in strings from the user and then perform checks if the data contains numerics or alphas or if the data is really pure, not a mixture of alpha and numerics making the code more robust and bug free. For that I created a class in which one needs to pass string and it will check it out what kind of data it is, based on it’s internal working while working with such mechanism creating multiple objects of the filter system class does not make sense because if one does so then all the objects would be identical in functionality and usage. Which clearly means that there would be no benefit if the class has multiple instances. So I ended up creating everything static because I did not wanted to create objects

1

The thing you asked about is called utility function.

There are lots of information, opinions, and mis-information about the role and propriety of utility functions in object-oriented world.

In your example, the utility function is very simple, so I would have preferred to keep it as a non-member#1 utility function. Your utility function has a very simple signature:

#1: Not a member of a class. However, it could still be placed into a namespace.

bool ValidateNumber(const std::string& str);

When the utility function is used in the context of user I/O (specifically console-based user I/O), the following logic is typically involved:

  • Subroutine “ask user for number and repeat until success”
    • Print prompt
    • Accept one line of text from user
    • Validate input (by calling the utility function above)
    • If validation fails,
      • Print an error message explaining what is wrong
      • Loop back to “Print prompt”, etc.
    • If validation succeeds, the converted number is returned from this subroutine.

Notice that this subroutine has plenty of states and logic. It has sufficient complexity that it can be made into a class and instantiated into an object. It could also be made customizable, e.g. allowing an application to instantiate two objects, each with a different prompt.

In graphical user interface (GUI), it is more often to see that a number-asking subroutine being wrapped into an object. This is because in the GUI world, a GUI element that asks for a number will have some unique designs, most notably a “spinbox” (a pair of up/down arrows which allow user to increment/decrement the number when clicked). This strongly favors converting the subroutine into an object.

It is perfectly fine to avoid making classes and use static functions. The fact that you only need one instance is effectively an indication that you don’t really need to define a class. This is especially true in C++ which is a multi-paradigm language.
If you need to group different filtering functions together, define a namespace.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật