designing pattern matching mechanism